From: Ulf Hermann <ulf.hermann@qt.io>
To: <elfutils-devel@sourceware.org>
Subject: [PATCH] Avoid signed/unsigned comparison
Date: Thu, 20 Apr 2017 14:40:00 -0000 [thread overview]
Message-ID: <1544575c-bba2-f196-3485-eb56b206b3d0@qt.io> (raw)
Some compilers implicitly cast the result of uint_fast16_t *
uint_fast16_t to something signed and then complain about the
comparison to (unsigned) size_t.
Casting phnum to size_t is a good idea anyway as 16bit multiplication
can easily overflow and we are not checking for this.
Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
libdwfl/ChangeLog | 4 ++++
libdwfl/elf-from-memory.c | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index cddafe2..c9bd4f0 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,9 @@
2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
+ * elf-from-memory.c: Explicitly cast phnum to size_t.
+
+2017-04-20 Ulf Hermann <ulf.hermann@qt.io>
+
* libdwflP.h: Don't include config.h.
* argp-std.c: Include config.h.
* cu.c: Likewise.
diff --git a/libdwfl/elf-from-memory.c b/libdwfl/elf-from-memory.c
index dd42e95..12a0a1b 100644
--- a/libdwfl/elf-from-memory.c
+++ b/libdwfl/elf-from-memory.c
@@ -172,7 +172,7 @@ elf_from_remote_memory (GElf_Addr ehdr_vma,
{
/* Read in the program headers. */
- if (initial_bufsize < phnum * phentsize)
+ if (initial_bufsize < (size_t)phnum * phentsize)
{
unsigned char *newbuf = realloc (buffer, phnum * phentsize);
if (newbuf == NULL)
--
2.1.4
next reply other threads:[~2017-04-20 14:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 14:40 Ulf Hermann [this message]
2017-04-27 22:35 ` Mark Wielaard
2017-04-28 10:35 ` Josh Stone
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=1544575c-bba2-f196-3485-eb56b206b3d0@qt.io \
--to=ulf.hermann@qt.io \
--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).