1
0
mirror of https://github.com/golang/go synced 2024-09-29 18:24:29 -06:00

cmd/cgo, runtime/cgo: avoid GCC/clang conversion warnings

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>
This commit is contained in:
Ian Lance Taylor 2021-09-09 14:04:43 -07:00
parent 73483df406
commit 426ff3746f
2 changed files with 7 additions and 7 deletions

View 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)

View 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();