]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Initialize tu_offset in __libdw_package_index
authorMark Wielaard <mark@klomp.org>
Fri, 1 Mar 2024 16:05:16 +0000 (17:05 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 1 Mar 2024 16:08:39 +0000 (17:08 +0100)
dwarf_cu_dwp_section_info.c: In function ‘__libdw_package_index’:
dwarf_cu_dwp_section_info.c:306:25: error: ‘tu_offset’ may be used uninitialized [-Werror=maybe-uninitialized]
  306 |               tu_offset += tu_index->section_count * 4;
      |               ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dwarf_cu_dwp_section_info.c:268:28: note: ‘tu_offset’ was declared here
  268 |       const unsigned char *tu_offset;
      |                            ^~~~~~~~~

Which is the same issue we thought to have fixed by checking for
tu_index != NULL but not all gcc versions seem able to see that.
So just explicitly initialize tu_offset to NULL. We keep the older
check, so the NULL pointer should never be used.

       * libdw/dwarf_cu_dwp_section_info.c (__libdw_package_index):
       Initialize tu_offset.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/dwarf_cu_dwp_section_info.c

index 9fdc15bf6875e03ebbaf7df8419b23453d381eb0..5a081f5ad5c37a767dc6f8d98b876bdd7cc3a3eb 100644 (file)
@@ -265,7 +265,7 @@ __libdw_package_index (Dwarf *dbg, bool tu)
       const unsigned char *cu_offset
        = cu_index->section_offsets + cu_index->sections[DW_SECT_INFO - 1] * 4;
       uint32_t tu_count = 0;
-      const unsigned char *tu_offset;
+      const unsigned char *tu_offset = NULL;
       if (tu_index != NULL)
        {
          tu_count = tu_index->unit_count;