public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid signed/unsigned comparison
@ 2017-04-20 14:40 Ulf Hermann
  2017-04-27 22:35 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Ulf Hermann @ 2017-04-20 14:40 UTC (permalink / raw)
  To: elfutils-devel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-28  0:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-20 14:40 [PATCH] Avoid signed/unsigned comparison Ulf Hermann
2017-04-27 22:35 ` Mark Wielaard
2017-04-28 10:35   ` Josh Stone

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).