]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 15 Oct 2017 15:16:26 +0000 (08:16 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 15 Oct 2017 15:16:37 +0000 (08:16 -0700)
realloc_check has

  unsigned char *magic_p;
...
  __libc_lock_lock (main_arena.mutex);
  const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
  __libc_lock_unlock (main_arena.mutex);
  if (!oldp)
    malloc_printerr ("realloc(): invalid pointer");
...
  if (newmem == NULL)
    *magic_p ^= 0xFF;

with

static void malloc_printerr(const char *str) __attribute__ ((noreturn));

GCC 7 -O3 warns

hooks.c: In function ‘realloc_check’:
hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     *magic_p ^= 0xFF;

due to the GCC bug:

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

This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT.

[BZ #22052]
* malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT
to silence -O3 -Wall warning with GCC 7.

ChangeLog
malloc/hooks.c

index eed74500f78def157a0834dca8c5d22bed069299..17fbe55b5df9f4407ba227cb944cec53ed66feaa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+       [BZ #22052]
+       * malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT
+       to silence -O3 -Wall warning with GCC 7.
+
 2017-10-14  H.J. Lu  <hongjiu.lu@intel.com>
 
        * Makeconfig (+link-static-before-libc): Use the first of
index 01be076f5ebc9e5038e06a8c6991608210aaa8d3..17d8907727752841d13c9198d489477486377840 100644 (file)
@@ -345,11 +345,18 @@ realloc_check (void *oldmem, size_t bytes, const void *caller)
       newmem = _int_realloc (&main_arena, oldp, oldsize, nb);
     }
 
+  DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+  /* GCC 7 warns about magic_p may be used uninitialized.  But we never
+     reach here if magic_p is uninitialized.  */
+  DIAG_IGNORE_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
+#endif
   /* mem2chunk_check changed the magic byte in the old chunk.
      If newmem is NULL, then the old chunk will still be used though,
      so we need to invert that change here.  */
   if (newmem == NULL)
     *magic_p ^= 0xFF;
+  DIAG_POP_NEEDS_COMMENT;
 
   __libc_lock_unlock (main_arena.mutex);