]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Declare possible zero sized arrays only when non-zero
authorMark Wielaard <mark@klomp.org>
Thu, 6 Jan 2022 16:58:59 +0000 (17:58 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 6 Jan 2022 16:58:59 +0000 (17:58 +0100)
The gcc undefined sanitizer complains when seeing a zero sized array
declaration. Move the declaration to the point in the code where we
know they aren't zero sized.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/link_map.c

index aace969fe42f283c0f5fd013af752785cdffdba6..b2588b129e171fa1be8fb08c1df1913a3a19bc0e 100644 (file)
@@ -1,3 +1,8 @@
+2022-01-03  Mark Wielaard  <mark@klomp.org>
+
+       * link_map.c (dwfl_link_map_report): Only declare d32 and d64 before
+       actual use.
+
 2022-01-03  Mark Wielaard  <mark@klomp.org>
 
        * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy
index 99222bb99dce0b0dac753b1e8b167718224459af..c0207cd39e8f411f7da05d3dfcd634a9f928cc96 100644 (file)
@@ -1037,8 +1037,6 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
                  return false;
                }
              void *buf = malloc (dyn_filesz);
-             Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
-             Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;
              if (unlikely (buf == NULL))
                {
                  __libdwfl_seterrno (DWFL_E_NOMEM);
@@ -1068,6 +1066,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
                  /* We are looking for DT_DEBUG.  */
                  if (elfclass == ELFCLASS32)
                    {
+                     Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
                      size_t n = dyn_filesz / sizeof (Elf32_Dyn);
                      for (size_t i = 0; i < n; ++i)
                        if ((*d32)[i].d_tag == DT_DEBUG)
@@ -1078,6 +1077,7 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
                    }
                  else
                    {
+                     Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;
                      size_t n = dyn_filesz / sizeof (Elf64_Dyn);
                      for (size_t i = 0; i < n; ++i)
                        if ((*d64)[i].d_tag == DT_DEBUG)