[4/6] libc/stdlib: Undefined shift negative value in a64l

Message ID 20200820221449.686006-5-keithp@keithp.com
State New
Headers show
Series
  • Fixes inspired by building with clang
Related show

Commit Message

R. Diez via Newlib Aug. 20, 2020, 10:14 p.m.
Shifting a negative value is not defined. Use an unsigned
value with the same bit pattern instead.

Signed-off-by: Keith Packard <keithp@keithp.com>

---
 newlib/libc/stdlib/a64l.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.28.0

Patch

diff --git a/newlib/libc/stdlib/a64l.c b/newlib/libc/stdlib/a64l.c
index dcac2e050..a8b1b6e45 100644
--- a/newlib/libc/stdlib/a64l.c
+++ b/newlib/libc/stdlib/a64l.c
@@ -177,7 +177,7 @@  a64l (const char *input)
 #if LONG_MAX > 2147483647
   /* for implementations where long is > 32 bits, the result must be sign-extended */
   if (result & 0x80000000)
-      return (((long)-1 >> 32) << 32) + result;
+      return (~0UL << 32) + result;
 #endif
 
   return result;