From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdwfl: Declare possible zero sized arrays only when non-zero
Date: Thu, 6 Jan 2022 18:02:22 +0100 [thread overview]
Message-ID: <20220106170222.130901-1-mark@klomp.org> (raw)
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 | 5 +++++
libdwfl/link_map.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index aace969f..b2588b12 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -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
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 99222bb9..c0207cd3 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)
--
2.30.2
reply other threads:[~2022-01-06 17:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220106170222.130901-1-mark@klomp.org \
--to=mark@klomp.org \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).