]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo, runtime/cgo: avoid GCC/clang conversion warnings
authorIan Lance Taylor <iant@golang.org>
Thu, 9 Sep 2021 21:04:43 +0000 (14:04 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 9 Sep 2021 22:18:05 +0000 (22:18 +0000)
Add explicit conversions to avoid warnings from -Wsign-conversion and
-Wshorten-64-to-32. Also avoid runtime errors from -fsanitize=undefined.

Fixes #48121

Change-Id: I29dc8d976884fc42826392c10f1e1759bb1a3989
Reviewed-on: https://go-review.googlesource.com/c/go/+/348739
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/cgo/out.go
src/runtime/cgo/gcc_sigaction.c

index 3badd73f7942288def0364a74b545ec2424ccda9..ee989b95e5daa5bc9214980fa1a826b36985baa3 100644 (file)
@@ -1458,10 +1458,10 @@ const gccProlog = `
   (have a negative array count) and an inscrutable error will come
   out of the compiler and hopefully mention "name".
 */
-#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
+#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2UL+1UL];
 
 /* Check at compile time that the sizes we use match our expectations. */
-#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), n, _cgo_sizeof_##t##_is_not_##n)
+#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), (size_t)n, _cgo_sizeof_##t##_is_not_##n)
 
 __cgo_size_assert(char, 1)
 __cgo_size_assert(short, 2)
index dd283151f17055c1061f1e2e850e62534de489e6..fcf1e50740e855765a2ff471472e8e3fdca53cc5 100644 (file)
@@ -49,13 +49,13 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
                sigemptyset(&act.sa_mask);
                for (i = 0; i < 8 * sizeof(goact->mask); i++) {
                        if (goact->mask & ((uint64_t)(1)<<i)) {
-                               sigaddset(&act.sa_mask, i+1);
+                               sigaddset(&act.sa_mask, (int)(i+1));
                        }
                }
-               act.sa_flags = goact->flags & ~SA_RESTORER;
+               act.sa_flags = (int)(goact->flags & ~(uint64_t)SA_RESTORER);
        }
 
-       ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
+       ret = sigaction((int)signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
        if (ret == -1) {
                // runtime.rt_sigaction expects _cgo_sigaction to return errno on error.
                _cgo_tsan_release();
@@ -70,11 +70,11 @@ x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *ol
                }
                oldgoact->mask = 0;
                for (i = 0; i < 8 * sizeof(oldgoact->mask); i++) {
-                       if (sigismember(&oldact.sa_mask, i+1) == 1) {
+                       if (sigismember(&oldact.sa_mask, (int)(i+1)) == 1) {
                                oldgoact->mask |= (uint64_t)(1)<<i;
                        }
                }
-               oldgoact->flags = oldact.sa_flags;
+               oldgoact->flags = (uint64_t)oldact.sa_flags;
        }
 
        _cgo_tsan_release();