Initialize strtok_r's saveptr to NULL
authorManish Goregaokar <manish@mozilla.com>
Wed, 29 Jun 2016 11:39:43 +0000 (17:09 +0530)
committerManish Goregaokar <manish@mozilla.com>
Wed, 29 Jun 2016 14:37:14 +0000 (20:07 +0530)
Building gdb with --enable-build-with-cxx=no trips on a warning:

 ../../binutils-gdb/gdb/rust-lang.c:173:15: error: saveptr may be used
 uninitialized in this function [-Werror=maybe-uninitialized]
     ret.name = concat (TYPE_NAME (type), "::", token, (char *) NULL);

The problem is that gcc doesn't understand that "tail" can never be
NULL in the call to strtok_r:

      name = xstrdup (TYPE_FIELD_NAME (type, 0));
      cleanup = make_cleanup (xfree, name);
      tail = name + strlen (RUST_ENUM_PREFIX);
...
      for (token = strtok_r (tail, "$", &saveptr);

Fix this by always initializing saveptr.

2016-06-29  Manish Goregaokar  <manish@mozilla.com>

gdb/ChangeLog:
    * rust-lang.c (rust_get_disr_info): Initialize saveptr to NULL.

gdb/ChangeLog
gdb/rust-lang.c

index e30e0995546c921aed3b21d3f68ef05eee001810..97b609bf2f5649233870b48705fe6e4159db8048 100644 (file)
@@ -1,5 +1,10 @@
 2016-06-29  Manish Goregaokar  <manish@mozilla.com>
 
+gdb/ChangeLog:
+       * rust-lang.c (rust_get_disr_info): Initialize saveptr to NULL.
+
+2016-06-29  Manish Goregaokar  <manish@mozilla.com>
+
 gdb/ChangeLog:
        * rust-lang.c (rust_get_disr_info): Use strtok_r instead of strsep.
 
index c01687a44805c2c079fe8f3e0d64cdb45945fafe..1849349f49a0866ec34eadaaadc7a05b4693781b 100644 (file)
@@ -121,7 +121,7 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
   if (strncmp (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX,
               strlen (RUST_ENUM_PREFIX)) == 0)
     {
-      char *tail, *token, *name, *saveptr;
+      char *tail, *token, *name, *saveptr = NULL;
       unsigned long fieldno;
       struct type *member_type;
       LONGEST value;