This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch] Fix gcc-4.7 memset zero-length warning
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: binutils at sourceware dot org
- Date: Thu, 9 Feb 2012 18:11:26 +0100
- Subject: [patch] Fix gcc-4.7 memset zero-length warning
Hi,
Fedora 17/Rawhide x86_64:
gcc-4.7.0-0.10.fc17.x86_64 (4.7.0 20120126)
glibc-headers-2.15-2.fc17.x86_64
CFLAGS="-D_FORTIFY_SOURCE=2 -O2" ./configure --enable-targets=all
make
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.
Thanks,
Jan
bfd/
2012-02-09 Jan Kratochvil <jan.kratochvil@redhat.com>
* oasys.c (oasys_write_header): Fix compilation warning on zero-sized
memset.
--- 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;