* elfedit false "may be used uninitialised"
@ 2020-11-09 3:51 Alan Modra
2020-12-29 18:39 ` [PATCH] elfedit: Pass osabi to reconcat H.J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2020-11-09 3:51 UTC (permalink / raw)
To: binutils
Found with gcc-7.5 -Og
elfedit.c:904:15: error: 'osabi' may be used uninitialised in this function [-Werror=maybe-uninitialized]
904 | osabi = concat (osabi, "|", osabis[i].name, NULL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* elfedit (usage): Avoid false positive "may be used uninitialised".
Don't leak memory.
diff --git a/binutils/elfedit.c b/binutils/elfedit.c
index 5fffe845d8..55474ffbbc 100644
--- a/binutils/elfedit.c
+++ b/binutils/elfedit.c
@@ -895,13 +895,10 @@ ATTRIBUTE_NORETURN static void
usage (FILE *stream, int exit_status)
{
unsigned int i;
- char *osabi;
+ char *osabi = concat (osabis[0].name, NULL);
- for (i = 0; i < ARRAY_SIZE (osabis); i++)
- if (i == 0)
- osabi = concat (osabis[i].name, NULL);
- else
- osabi = concat (osabi, "|", osabis[i].name, NULL);
+ for (i = 1; i < ARRAY_SIZE (osabis); i++)
+ osabi = reconcat (osabi, "|", osabis[i].name, NULL);
fprintf (stream, _("Usage: %s <option(s)> elffile(s)\n"),
program_name);
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] elfedit: Pass osabi to reconcat
2020-11-09 3:51 elfedit false "may be used uninitialised" Alan Modra
@ 2020-12-29 18:39 ` H.J. Lu
2020-12-30 3:10 ` Alan Modra
0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2020-12-29 18:39 UTC (permalink / raw)
To: Alan Modra; +Cc: Binutils
[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]
On Sun, Nov 8, 2020 at 7:52 PM Alan Modra via Binutils
<binutils@sourceware.org> wrote:
>
> Found with gcc-7.5 -Og
>
> elfedit.c:904:15: error: 'osabi' may be used uninitialised in this function [-Werror=maybe-uninitialized]
> 904 | osabi = concat (osabi, "|", osabis[i].name, NULL);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> * elfedit (usage): Avoid false positive "may be used uninitialised".
> Don't leak memory.
>
> diff --git a/binutils/elfedit.c b/binutils/elfedit.c
> index 5fffe845d8..55474ffbbc 100644
> --- a/binutils/elfedit.c
> +++ b/binutils/elfedit.c
> @@ -895,13 +895,10 @@ ATTRIBUTE_NORETURN static void
> usage (FILE *stream, int exit_status)
> {
> unsigned int i;
> - char *osabi;
> + char *osabi = concat (osabis[0].name, NULL);
>
> - for (i = 0; i < ARRAY_SIZE (osabis); i++)
> - if (i == 0)
> - osabi = concat (osabis[i].name, NULL);
> - else
> - osabi = concat (osabi, "|", osabis[i].name, NULL);
> + for (i = 1; i < ARRAY_SIZE (osabis); i++)
> + osabi = reconcat (osabi, "|", osabis[i].name, NULL);
>
> fprintf (stream, _("Usage: %s <option(s)> elffile(s)\n"),
> program_name);
>
I checked in this.
--
H.J.
[-- Attachment #2: 0001-elfedit-Pass-osabi-to-reconcat.patch --]
[-- Type: application/x-patch, Size: 1547 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elfedit: Pass osabi to reconcat
2020-12-29 18:39 ` [PATCH] elfedit: Pass osabi to reconcat H.J. Lu
@ 2020-12-30 3:10 ` Alan Modra
0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2020-12-30 3:10 UTC (permalink / raw)
To: H.J. Lu; +Cc: Binutils
On Tue, Dec 29, 2020 at 10:39:57AM -0800, H.J. Lu wrote:
> I checked in this.
>
> diff --git a/binutils/elfedit.c b/binutils/elfedit.c
> index dc2f722d38..e54011c9a8 100644
> --- a/binutils/elfedit.c
> +++ b/binutils/elfedit.c
> @@ -902,7 +902,7 @@ usage (FILE *stream, int exit_status)
> char *osabi = concat (osabis[0].name, NULL);
>
> for (i = 1; i < ARRAY_SIZE (osabis); i++)
> - osabi = reconcat (osabi, "|", osabis[i].name, NULL);
> + osabi = reconcat (osabi, osabi, "|", osabis[i].name, NULL);
>
> fprintf (stream, _("Usage: %s <option(s)> elffile(s)\n"),
> program_name);
>
Thanks!
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-30 3:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 3:51 elfedit false "may be used uninitialised" Alan Modra
2020-12-29 18:39 ` [PATCH] elfedit: Pass osabi to reconcat H.J. Lu
2020-12-30 3:10 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).