This is the mail archive of the binutils@sourceware.org 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]

Re: [PATCH] remove pointless assignment


Trevor,

I just checked the man page on snprintf.  Wouldn't,

snprintf(regname, sizeof(regname), "$vf%d", i);

be more appropriate?  According to the manpage, the size parameter needs
to include the null termination.

Dan

P.S.  My apologies if this is a duplicate msg ...

On Thu, 2016-04-14 at 17:36 -0400, tbsaunde+binutils@tbsaunde.org wrote:
> From: Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
> 
> Hi,
> 
> Presumably this was supposed to be regname[sizeof (regname) - 1] but was typoed
> to regname[sizeof (rename) - 1].  However that should be unnecessary because
> sprintf should null terminate.  As is this assignment is invalid ISO C because
> rename refers to the function rename (), and sizeof on functions is undefined.
> In GNU C C the size of functions is 1 so the expression is the same as
> regname[0].  The following call to sprintf () clearly will over right that, so
> the statement either has no effect or is invalid.  Given that it seems safe to
> just remove it.
> 
> built and regtested cross to mips64-elf, ok?
> 
> Trev
> 
> gas/ChangeLog:
> 
> 2016-04-14  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>
> 
> 	* config/tc-mips.c (md_begin): Remove useless assignment.
> ---
>  gas/config/tc-mips.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c
> index 118b91d..f3dbd5f 100644
> --- a/gas/config/tc-mips.c
> +++ b/gas/config/tc-mips.c
> @@ -3604,7 +3604,6 @@ md_begin (void)
>        char regname[7];
>  
>        /* R5900 VU0 floating-point register.  */
> -      regname[sizeof (rename) - 1] = 0;
>        snprintf (regname, sizeof (regname) - 1, "$vf%d", i);
>        symbol_table_insert (symbol_new (regname, reg_section,
>  				       RTYPE_VF | i, &zero_address_frag));


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