Fix -Wstringop-overflow warning in ecoff_link_hash_newfunc

Message ID mvmcykq63vz.fsf@suse.de
State New
Headers
Series Fix -Wstringop-overflow warning in ecoff_link_hash_newfunc |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 warning Patch is already merged

Commit Message

Andreas Schwab Sept. 26, 2024, 11:38 a.m. UTC
  * ecoff.c (ecoff_link_hash_newfunc): Don't call memset if ret is
	NULL.
---
 bfd/ecoff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jan Beulich Sept. 26, 2024, 11:50 a.m. UTC | #1
On 26.09.2024 13:38, Andreas Schwab wrote:
> 	* ecoff.c (ecoff_link_hash_newfunc): Don't call memset if ret is
> 	NULL.
> ---
>  bfd/ecoff.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/bfd/ecoff.c b/bfd/ecoff.c
> index 04501761bd6..5ee7ffaf489 100644
> --- a/bfd/ecoff.c
> +++ b/bfd/ecoff.c
> @@ -3278,8 +3278,8 @@ ecoff_link_hash_newfunc (struct bfd_hash_entry *entry,
>        ret->abfd = NULL;
>        ret->written = 0;
>        ret->small = 0;
> +      memset ((void *) &ret->esym, 0, sizeof ret->esym);
>      }
> -  memset ((void *) &ret->esym, 0, sizeof ret->esym);
>  
>    return (struct bfd_hash_entry *) ret;
>  }

Okay (and likely obvious anyway). I'd like to note though that the bad case
can't happen in practice, afaict, as _bfd_link_hash_newfunc() won't ever
return NULL when passed non-NULL.

Jan
  
Andreas Schwab Sept. 26, 2024, 11:56 a.m. UTC | #2
On Sep 26 2024, Jan Beulich wrote:

> Okay (and likely obvious anyway). I'd like to note though that the bad case
> can't happen in practice, afaict, as _bfd_link_hash_newfunc() won't ever
> return NULL when passed non-NULL.

Right, that's why I changed the original subject "Fix NULL pointer
dereference" into this one.  With enough of inlining the compiler should
be able to figure that out by itself, though.
  

Patch

diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 04501761bd6..5ee7ffaf489 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -3278,8 +3278,8 @@  ecoff_link_hash_newfunc (struct bfd_hash_entry *entry,
       ret->abfd = NULL;
       ret->written = 0;
       ret->small = 0;
+      memset ((void *) &ret->esym, 0, sizeof ret->esym);
     }
-  memset ((void *) &ret->esym, 0, sizeof ret->esym);
 
   return (struct bfd_hash_entry *) ret;
 }