From: Mark Wielaard Date: Thu, 6 Jan 2022 16:58:59 +0000 (+0100) Subject: libdwfl: Declare possible zero sized arrays only when non-zero X-Git-Tag: elfutils-0.187~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04a5fd7400429398e096ccd1b32f71a1f1c8db76;p=thirdparty%2Felfutils.git libdwfl: Declare possible zero sized arrays only when non-zero 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 --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index aace969fe..b2588b129 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2022-01-03 Mark Wielaard + + * link_map.c (dwfl_link_map_report): Only declare d32 and d64 before + actual use. + 2022-01-03 Mark Wielaard * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index 99222bb99..c0207cd39 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -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)