libdw: Initialize filelist earlier in dwarf_getsrclines.c read_srclines.
authorLuiz Angelo Daros de Luca <luizluca@gmail.com>
Sun, 17 Jun 2018 09:34:08 +0000 (11:34 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 18 Jun 2018 11:28:48 +0000 (13:28 +0200)
I'm getting this error with 0.172:

dwarf_getsrclines.c: In function 'read_srclines':
dwarf_getsrclines.c:1074:7: error: 'filelist' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       free (filelist);
       ^~~~~~~~~~~~~~~

It seems that gcc is right here as there is "ifs" that go to "out"
(where filelist is freed) before freelist is initialized.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
libdw/ChangeLog
libdw/dwarf_getsrclines.c

index 329a994..bed6379 100644 (file)
@@ -1,3 +1,7 @@
+2018-06-17  Luiz Angelo Daros de Luca  <luizluca@gmail.com>
+
+       * dwarf_getsrclines.c (read_srclines): Intialize filelist early.
+
 2018-06-15  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_getlocation.c (check_constant_offset): Clarify DW_FORM_data16
index bb512ec..8510538 100644 (file)
@@ -153,6 +153,7 @@ read_srclines (Dwarf *dbg,
 {
   int res = -1;
 
+  struct filelist *filelist = NULL;
   size_t nfilelist = 0;
   size_t ndirlist = 0;
 
@@ -445,7 +446,7 @@ read_srclines (Dwarf *dbg,
       },
       .next = NULL
     };
-  struct filelist *filelist = &null_file;
+  filelist = &null_file;
   nfilelist = 1;
 
   /* Allocate memory for a new file.  For the first MAX_STACK_FILES