This is the mail archive of the mailing list for the binutils 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] Fix gcc-4.7 memset zero-length warning


Fedora 17/Rawhide x86_64:
gcc-4.7.0-0.10.fc17.x86_64 (4.7.0 20120126)

CFLAGS="-D_FORTIFY_SOURCE=2 -O2" ./configure --enable-targets=all

In file included from /usr/include/string.h:642:0,
                 from sysdep.h:44,
                 from oasys.c:25:
In function ‘memset’,
    inlined from ‘oasys_write_object_contents’ at oasys.c:911:3:
/usr/include/bits/string3.h:82:30: error: call to ‘__warn_memset_zero_len’ declared with attribute warning: memset used with constant zero length parameter; this could be due to transposed parameters [-Werror]

__extern_always_inline void *
__NTH (memset (void *__dest, int __ch, size_t __len))
  if (__builtin_constant_p (__len) && __len == 0
      && (!__builtin_constant_p (__ch) || __ch != 0))
      __warn_memset_zero_len ();
      return __dest;
  return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));

But in some way it may be more GCC bug.  OK to check it in or not?  I did not
report it to GCC.


2012-02-09  Jan Kratochvil  <>

	* oasys.c (oasys_write_header): Fix compilation warning on zero-sized

--- a/bfd/oasys.c
+++ b/bfd/oasys.c
@@ -906,9 +906,11 @@ oasys_write_header (bfd *abfd)
   if (length > (size_t) sizeof (r.module_name))
     length = sizeof (r.module_name);
+  else
+    (void) memset (r.module_name + length, ' ',
+		   sizeof (r.module_name) - length);
   (void) memcpy (r.module_name, abfd->filename, length);
-  (void) memset (r.module_name + length, ' ', sizeof (r.module_name) - length);
   r.version_number = OASYS_VERSION_NUMBER;
   r.rev_number = OASYS_REV_NUMBER;

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