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

Keith Packard keithp@keithp.com
Thu Aug 20 22:14:47 GMT 2020


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

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;
-- 
2.28.0



More information about the Newlib mailing list