Skip to contentSkip to conversation

scripts/sortextable: Suppress warning: ‘relocs_size’ may be used uninitialized

PATCH In review [email protected] 2 participants 2 messages Sep 16, 2014 – Sep 18, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/sortextable: Suppress warning: ‘relocs_size’ may be used uninitialized

From: Tim Gardner <[email protected]>

In file included from scripts/sortextable.c:194:0:
scripts/sortextable.c: In function ‘main’:
scripts/sortextable.h:176:3: warning: ‘relocs_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]
memset(relocs, 0, relocs_size);
^
scripts/sortextable.h:106:6: note: ‘relocs_size’ was declared here

  int relocs_size;
      ^

In file included from scripts/sortextable.c:192:0:
scripts/sortextable.h:176:3: warning: ‘relocs_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]
memset(relocs, 0, relocs_size);
^
scripts/sortextable.h:106:6: note: ‘relocs_size’ was declared here

  int relocs_size;
      ^

gcc 4.9.1

Cc Andrew Morton <[email protected]>
Cc Jamie Iles <[email protected]>

---

Is gcc 4.9 dumber then 4.8 ? gcc 4.8 doesn't produce this warning.

 scripts/sortextable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/sortextable.h +1 -1
index 8fac3fd..ba87004 100644
@@ -103,7 +103,7 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
 	Elf_Sym *sort_needed_sym;
 	Elf_Shdr *sort_needed_sec;
 	Elf_Rel *relocs = NULL;
-	int relocs_size;
+	int relocs_size = 0;
 	uint32_t *sort_done_location;
 	const char *secstrtab;
 	const char *strtab;
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Tim,

Quoted 18 lines · On Tue, Sep 16, 2014 at 12:49:22PM -0600, [email protected] wrote:

From: Tim Gardner <[email protected]>

In file included from scripts/sortextable.c:194:0:
scripts/sortextable.c: In function ‘main’:
scripts/sortextable.h:176:3: warning: ‘relocs_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]

   memset(relocs, 0, relocs_size);
   ^
scripts/sortextable.h:106:6: note: ‘relocs_size’ was declared here
  int relocs_size;
      ^
In file included from scripts/sortextable.c:192:0:
scripts/sortextable.h:176:3: warning: ‘relocs_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   memset(relocs, 0, relocs_size);
   ^
scripts/sortextable.h:106:6: note: ‘relocs_size’ was declared here
  int relocs_size;
      ^
Quoted 4 lines

gcc 4.9.1

Cc Andrew Morton <[email protected]>
Cc Jamie Iles <[email protected]>
Quoted 4 lines

---

Is gcc 4.9 dumber then 4.8 ? gcc 4.8 doesn't produce this warning.

It's an odd one - I don't see how relocs_size can be uninitialized when relocs is non-null. Your fix looks fine to me though.

Jamie

Quoted 19 lines
 scripts/sortextable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/sortextable.h +1 -1
index 8fac3fd..ba87004 100644
@@ -103,7 +103,7 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
 	Elf_Sym *sort_needed_sym;
 	Elf_Shdr *sort_needed_sec;
 	Elf_Rel *relocs = NULL;
-	int relocs_size;
+	int relocs_size = 0;
 	uint32_t *sort_done_location;
 	const char *secstrtab;
 	const char *strtab;
Signature · 1 line
2.1.0