When building with gcc -Os it seems we can inline read_number_entries
but if that function fails then n will not be initialized. GCC seems not
to realize that in that case n won't be used at all. Explicitly initialize
n to zero to prevent a spurious error: 'n' may be used uninitialized in
this function [-Werror=maybe-uninitialized] in that case.

https://sourceware.org/bugzilla/show_bug.cgi?id=21011

Signed-off-by: Mark Wielaard <m...@klomp.org>
---
 libelf/ChangeLog      | 4 ++++
 libelf/elf_getarsym.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 23a4fb9..d425e50 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-19  Mark Wielaard  <m...@klomp.org>
+
+       * elf_getarsym.c (elf_getarsym): Initialize n to zero.
+
 2017-03-27  Mark Wielaard  <m...@klomp.org>
 
        * elf32_updatefile.c (updatemmap): Always update last_positition.
diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
index d5f0ba4..1f031fc 100644
--- a/libelf/elf_getarsym.c
+++ b/libelf/elf_getarsym.c
@@ -167,7 +167,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
 
       /* We have an archive.  The first word in there is the number of
         entries in the table.  */
-      uint64_t n;
+      uint64_t n = 0;
       size_t off = elf->start_offset + SARMAG + sizeof (struct ar_hdr);
       if (read_number_entries (&n, elf, &off, index64_p) < 0)
        {
-- 
1.8.3.1

Reply via email to