From 9817fdd04f66a3e04f6b953fd4ddc3443e98388b Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 11 May 2017 11:21:01 +0300 Subject: [PATCH] Eliminate 'value shift followed by expansion' false code defect warning * src/atomic_ops.c [AO_USE_NANOSLEEP] (AO_pause): Use "L" suffix for shifted immediate value (1) to match the type of ts.tv_nsec. * src/atomic_ops.c [!AO_USE_NANOSLEEP && AO_USE_WIN32_PTHREADS] (AO_pause): Cast shifted immediate value (1) to DWORD to match Sleep argument type. * src/atomic_ops.c [!AO_USE_NANOSLEEP && !AO_USE_WIN32_PTHREADS] (AO_pause): Store computed usec value to an intermediate int variable (before storing it to tv.tv_usec) so that to avoid widening conversion of shifted immediate int value (1); add comment. --- src/atomic_ops.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/atomic_ops.c b/src/atomic_ops.c index c9209a3..636d9ce 100644 --- a/src/atomic_ops.c +++ b/src/atomic_ops.c @@ -243,15 +243,20 @@ void AO_pause(int n) # ifdef AO_USE_NANOSLEEP struct timespec ts; ts.tv_sec = 0; - ts.tv_nsec = (n > 28 ? 100000 * 1000 : 1 << (n - 2)); + ts.tv_nsec = n > 28 ? 100000L * 1000 : 1L << (n - 2); nanosleep(&ts, 0); # elif defined(AO_USE_WIN32_PTHREADS) - Sleep(n > 28 ? 100 : n < 22 ? 1 : 1 << (n - 22)); /* in millis */ + Sleep(n > 28 ? 100 /* millis */ + : n < 22 ? 1 : (DWORD)1 << (n - 22)); # else struct timeval tv; /* Short async-signal-safe sleep. */ + int usec = n > 28 ? 100000 : 1 << (n - 12); + /* Use an intermediate variable (of int type) to avoid */ + /* "shift followed by widening conversion" warning. */ + tv.tv_sec = 0; - tv.tv_usec = n > 28 ? 100000 : 1 << (n - 12); + tv.tv_usec = usec; select(0, 0, 0, 0, &tv); # endif } -- 2.7.4