public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFA: Libiberty: Fix warnings about left shifting a negative value.
@ 2015-12-18 12:17 Nick Clifton
  2015-12-19  2:21 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Nick Clifton @ 2015-12-18 12:17 UTC (permalink / raw)
  To: dj, iant; +Cc: gcc-patches

Hi DJ, Hi Ian,

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

  OK to apply ?

Cheers
  Nick

PS: Running the libiberty testsuite with -fsanitize=undefined does throw
  up a couple more runtime errors:

libiberty/cplus-dem.c:503:13: runtime error: signed integer overflow: 922337203 * 10 cannot be represented in type 'int'
libiberty/cp-demangle.c:4123:40: runtime error: variable length array bound evaluates to non-positive value 0
libiberty/cp-demangle.c:4124:43: runtime error: variable length array bound evaluates to non-positive value 0

  I have not attempted to fix these.  The first looks like it is a
  deliberate piece of coding and the other two look unimportant since
  the zero sized arrays will never be used. 

libiberty/ChangeLog
2015-12-18  Nick Clifton  <nickc@redhat.com>

	PR 66827
	* regex.c (EXTRACT_NUMBER): Cast sign byte to unsigned before left
	shifting.

Index: libiberty/regex.c
===================================================================
--- libiberty/regex.c	(revision 231805)
+++ libiberty/regex.c	(working copy)
@@ -685,7 +685,7 @@
 #  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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: RFA: Libiberty: Fix warnings about left shifting a negative value.
  2015-12-18 12:17 RFA: Libiberty: Fix warnings about left shifting a negative value Nick Clifton
@ 2015-12-19  2:21 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2015-12-19  2:21 UTC (permalink / raw)
  To: Nick Clifton; +Cc: DJ Delorie, gcc-patches

On Fri, Dec 18, 2015 at 4:17 AM, Nick Clifton <nickc@redhat.com> wrote:
>
> 2015-12-18  Nick Clifton  <nickc@redhat.com>
>
>         PR 66827
>         * regex.c (EXTRACT_NUMBER): Cast sign byte to unsigned before left
>         shifting.

This is OK.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-19  2:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-18 12:17 RFA: Libiberty: Fix warnings about left shifting a negative value Nick Clifton
2015-12-19  2:21 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).