This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/3] libiberty: fix warnings about left shifting a negative value.


From: Nick Clifton <nickc@redhat.com>

  GCC PR 66827 reports some problems with left shifting a negative
  value:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66827

  Of the problems reported only two remain - in libiberty/regex.c:

libiberty/regex.c:6970:11: runtime error: left shift of negative value -1
libiberty/regex.c:7165:4: runtime error: left shift of negative value -1

  The patch below fixes these errors by casting the value to be shifted
  to unsigned before the shift occurs.

  No regressions were found in the libiberty testsuite or bootstrapping
  gcc (on an x86_64 target).
---
 libiberty/ChangeLog | 6 ++++++
 libiberty/regex.c   | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 3d2ff59..e8fc96a 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-21  Nick Clifton  <nickc@redhat.com>
+
+	PR 66827
+	* regex.c (EXTRACT_NUMBER): Cast sign byte to unsigned before left
+	shifting.
+
 2015-11-27  Pedro Alves  <palves@redhat.com>
 
 	PR other/61321
diff --git a/libiberty/regex.c b/libiberty/regex.c
index 16338cb..9ffc3f4 100644
--- a/libiberty/regex.c
+++ b/libiberty/regex.c
@@ -685,7 +685,7 @@ typedef enum
 #  define EXTRACT_NUMBER(destination, source)				\
   do {									\
     (destination) = *(source) & 0377;					\
-    (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8;		\
+    (destination) += ((unsigned) SIGN_EXTEND_CHAR (*((source) + 1))) << 8; \
   } while (0)
 # endif
 
-- 
2.6.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]