This is the mail archive of the
mailing list for the binutils project.
Re: [PATCH] remove pointless assignment
- From: Dan <dgisselq at verizon dot net>
- To: tbsaunde+binutils at tbsaunde dot org
- Cc: binutils at sourceware dot org
- Date: Thu, 14 Apr 2016 19:01:19 -0400
- Subject: Re: [PATCH] remove pointless assignment
- Authentication-results: sourceware.org; auth=none
- References: <1460669815-11911-1-git-send-email-tbsaunde+binutils at tbsaunde dot org>
- Reply-to: dgisselq at ieee dot org
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.
P.S. My apologies if this is a duplicate msg ...
On Thu, 2016-04-14 at 17:36 -0400, email@example.com wrote:
> From: Trevor Saunders <firstname.lastname@example.org>
> 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. 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?
> 2016-04-14 Trevor Saunders <email@example.com>
> * 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;
> /* 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));