Fix for -Wstringop-overflow false positive

Michael Matz matz@suse.de
Thu Oct 17 15:48:50 GMT 2024


the way the overflow check was written wasn't understood by some
GCC versions and produced false positives for the memset call being
called potentially with object sizes that are larger than half
address-space.
---
My last change triggered the sourceware builder 
( https://builder.sourceware.org/buildbot/#/builders/305/builds/455 )
As usual with -Wstringop-overflow invalidly so, but ... whatever.
Applied as obvious.

 bfd/merge.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bfd/merge.c b/bfd/merge.c
index c811bc57eae..abb0269227e 100644
--- a/bfd/merge.c
+++ b/bfd/merge.c
@@ -181,9 +181,9 @@ sec_merge_maybe_resize (struct sec_merge_hash *table, unsigned added)
 
       do
 	{
-	  newnb *= 2;
-	  if (!(unsigned int)newnb)
+	  if (newnb >> (8 * sizeof(mapofs_type) - 1))
 	    return false;
+	  newnb *= 2;
 	}
       while (NEEDS_RESIZE (bfdtab->count + added, newnb));
 
-- 
2.42.0


More information about the Binutils mailing list