]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Initialize n to zero in elf_getarsym.
authorMark Wielaard <mark@klomp.org>
Wed, 19 Apr 2017 15:07:46 +0000 (17:07 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 19 Apr 2017 15:11:08 +0000 (17:11 +0200)
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 <mark@klomp.org>
libelf/ChangeLog
libelf/elf_getarsym.c

index 23a4fb93dd7fabd551a92c4be659d7dc939d4fc9..d425e50a7201c1e0fbc7ab719784a32ca94687e1 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-19  Mark Wielaard  <mark@klomp.org>
+
+       * elf_getarsym.c (elf_getarsym): Initialize n to zero.
+
 2017-03-27  Mark Wielaard  <mark@klomp.org>
 
        * elf32_updatefile.c (updatemmap): Always update last_positition.
index d5f0ba4346897251aff5a2e0e9c492ee76431ac1..1f031fcaab4988b977b1e439ca381122ef92444a 100644 (file)
@@ -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)
        {