elfedit false "may be used uninitialised"

Alan Modra amodra@gmail.com
Mon Nov 9 03:51:17 GMT 2020


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


More information about the Binutils mailing list