[COMMITTED] tests: Check symtabshdr instead of symtabndx in elfstrmerge.c.

Mark Wielaard mark@klomp.org
Thu Jan 25 13:41:00 GMT 2018


Some gcc omptimization levels (-Og in particular) didn't see that when
symtabndx != 0, then symtabshdr was certain to be initialized. Change
the symtabndx == 0 check to symtabshdr == NULL and initialize symtabshdr
to work around that.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/ChangeLog     | 11 ++++++++---
 tests/elfstrmerge.c |  4 ++--
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 758f20e..be203ad 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-25  Mark Wielaard  <mark@klomp.org>
+
+	* elfstrmerge.c (main): Initialize and check symtabshdr instead of
+	symtabndx.
+
 2018-01-14  Petr Machata  <pmachata@gmail.com>
 
 	* testfile-sizes4.o.bz2: New test file.
 
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 8d5b53c..6924d0e 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -195,7 +195,7 @@ main (int argc, char **argv)
   size_t symtabndx = 0;
   Elf_Scn *symtabscn = NULL;
   GElf_Shdr symtabshdr_mem;
-  GElf_Shdr *symtabshdr;
+  GElf_Shdr *symtabshdr = NULL;
   while ((symtabscn = elf_nextscn (elf, symtabscn)) != NULL)
     {
       symtabshdr = gelf_getshdr (symtabscn, &symtabshdr_mem);
@@ -210,7 +210,7 @@ main (int argc, char **argv)
 	}
     }
 
-  if (symtabndx == 0)
+  if (symtabshdr == NULL)
     fail ("No symtab found", fname);
 
   if ((symtabshdr->sh_flags & SHF_ALLOC) != 0)
-- 
1.8.3.1



More information about the Elfutils-devel mailing list