public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/3] libiberty: dupargv: rewrite to use xstrdup
  2016-01-05 20:05 [PATCH 0/3] libiberty: sync w/gcc [committed] Mike Frysinger
  2016-01-05 20:05 ` [PATCH 2/3] libiberty: Tweak the documentation of libiberty's xcrc32 function Mike Frysinger
@ 2016-01-05 20:05 ` Mike Frysinger
  2016-01-05 20:05 ` [PATCH 1/3] libiberty: fix warnings about left shifting a negative value Mike Frysinger
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2016-01-05 20:05 UTC (permalink / raw)
  To: gdb-patches

This func is basically open coding the xstrdup function, so gut it
and use it directly.
---
 libiberty/ChangeLog | 4 ++++
 libiberty/argv.c    | 6 +-----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index aa598f2..ba1e0a5 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,7 @@
+2016-01-05  Mike Frysinger  <vapier@gentoo.org>
+
+	* argv.c (dupargv): Replace strlen/xmalloc/strcpy with xstrdup.
+
 2015-12-28  Patrick Palka  <ppalka@gcc.gnu.org>
 
 	* crc32.c: In the documentation, don't refer to GDB's
diff --git a/libiberty/argv.c b/libiberty/argv.c
index f2727e8..5c3dd70 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -76,11 +76,7 @@ dupargv (char **argv)
 
   /* the strings */
   for (argc = 0; argv[argc] != NULL; argc++)
-    {
-      int len = strlen (argv[argc]);
-      copy[argc] = (char *) xmalloc (len + 1);
-      strcpy (copy[argc], argv[argc]);
-    }
+    copy[argc] = xstrdup (argv[argc]);
   copy[argc] = NULL;
   return copy;
 }
-- 
2.6.2

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

* [PATCH 1/3] libiberty: fix warnings about left shifting a negative value.
  2016-01-05 20:05 [PATCH 0/3] libiberty: sync w/gcc [committed] Mike Frysinger
  2016-01-05 20:05 ` [PATCH 2/3] libiberty: Tweak the documentation of libiberty's xcrc32 function Mike Frysinger
  2016-01-05 20:05 ` [PATCH 3/3] libiberty: dupargv: rewrite to use xstrdup Mike Frysinger
@ 2016-01-05 20:05 ` Mike Frysinger
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2016-01-05 20:05 UTC (permalink / raw)
  To: gdb-patches

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

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

* [PATCH 2/3] libiberty: Tweak the documentation of libiberty's xcrc32 function
  2016-01-05 20:05 [PATCH 0/3] libiberty: sync w/gcc [committed] Mike Frysinger
@ 2016-01-05 20:05 ` Mike Frysinger
  2016-01-05 20:05 ` [PATCH 3/3] libiberty: dupargv: rewrite to use xstrdup Mike Frysinger
  2016-01-05 20:05 ` [PATCH 1/3] libiberty: fix warnings about left shifting a negative value Mike Frysinger
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2016-01-05 20:05 UTC (permalink / raw)
  To: gdb-patches

From: Patrick Palka <patrick@parcs.ath.cx>

In some places the xcrc32 documentation refers to GDB's own crc32
implementation, but GDB no longer has its own crc32 implementation.
It now uses libiberty's xcrc32 throughout.  So this patch removes
these references to GDB's now-nonexistent crc32 implementation.

Also, there appears to be a bug in the table-generation program embedded
within the documentation.  When the variable "int i" is >= 128, the
computation "i << 24" shifts a one bit into the sign bit (assuming a
32-bit int), which is UB.  To avoid this UB, I think it is sufficient to
make the induction variables i and j have type unsigned int.  This bug
seems latent, however.  I ran the program before and after this change
and the table output is the same.
---
 libiberty/ChangeLog |  8 ++++++++
 libiberty/crc32.c   | 12 +++++-------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index e8fc96a..aa598f2 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,11 @@
+2015-12-28  Patrick Palka  <ppalka@gcc.gnu.org>
+
+	* crc32.c: In the documentation, don't refer to GDB's
+	now-nonexistent crc32 implementation.  In the table-generation
+	program embedded within the documentation, change the type of
+	the induction variables i and j from int to unsigned int, to
+	avoid undefined behavior.
+
 2015-12-21  Nick Clifton  <nickc@redhat.com>
 
 	PR 66827
diff --git a/libiberty/crc32.c b/libiberty/crc32.c
index 12d9be0..52c982f 100644
--- a/libiberty/crc32.c
+++ b/libiberty/crc32.c
@@ -33,15 +33,14 @@
 
 #include "libiberty.h"
 
-/* This table was generated by the following program.  This matches
-   what gdb does.
+/* This table was generated by the following program.
 
    #include <stdio.h>
 
    int
    main ()
    {
-     int i, j;
+     unsigned int i, j;
      unsigned int c;
      int table[256];
 
@@ -146,10 +145,9 @@ starting value is @var{init}; this may be used to compute the CRC of
 data split across multiple buffers by passing the return value of each
 call as the @var{init} parameter of the next.
 
-This is intended to match the CRC used by the @command{gdb} remote
-protocol for the @samp{qCRC} command.  In order to get the same
-results as gdb for a block of data, you must pass the first CRC
-parameter as @code{0xffffffff}.
+This is used by the @command{gdb} remote protocol for the @samp{qCRC}
+command.  In order to get the same results as gdb for a block of data,
+you must pass the first CRC parameter as @code{0xffffffff}.
 
 This CRC can be specified as:
 
-- 
2.6.2

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

* [PATCH 0/3] libiberty: sync w/gcc [committed]
@ 2016-01-05 20:05 Mike Frysinger
  2016-01-05 20:05 ` [PATCH 2/3] libiberty: Tweak the documentation of libiberty's xcrc32 function Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mike Frysinger @ 2016-01-05 20:05 UTC (permalink / raw)
  To: gdb-patches

Mike Frysinger (1):
  libiberty: dupargv: rewrite to use xstrdup

Nick Clifton (1):
  libiberty: fix warnings about left shifting a negative value.

Patrick Palka (1):
  libiberty: Tweak the documentation of libiberty's xcrc32 function

 libiberty/ChangeLog | 18 ++++++++++++++++++
 libiberty/argv.c    |  6 +-----
 libiberty/crc32.c   | 12 +++++-------
 libiberty/regex.c   |  2 +-
 4 files changed, 25 insertions(+), 13 deletions(-)

-- 
2.6.2

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

end of thread, other threads:[~2016-01-05 20:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05 20:05 [PATCH 0/3] libiberty: sync w/gcc [committed] Mike Frysinger
2016-01-05 20:05 ` [PATCH 2/3] libiberty: Tweak the documentation of libiberty's xcrc32 function Mike Frysinger
2016-01-05 20:05 ` [PATCH 3/3] libiberty: dupargv: rewrite to use xstrdup Mike Frysinger
2016-01-05 20:05 ` [PATCH 1/3] libiberty: fix warnings about left shifting a negative value Mike Frysinger

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