This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] Avoid signed/unsigned comparison
- From: Ulf Hermann <ulf dot hermann at qt dot io>
- To: <elfutils-devel at sourceware dot org>
- Date: Thu, 20 Apr 2017 16:40:30 +0200
- Subject: [PATCH] Avoid signed/unsigned comparison
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=qt.io;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qtcompany.onmicrosoft.com; s=selector1-qt-io; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DXA7/jCUHHx6Y6W/oPUGbFEZarHaKpySMk/s24/efQU=; b=tRF7Gq8Ma4i85R1/8FzffypsirHDLrP8nCkHonBYp4JfCRVEzmwcDpuRvcIyDob3lMN8J/imYybSYlOrWD40HUCLoewRSwuppecf7FlsaQDfrM9S/4akn+SpYpNyB6B6b/5OqQg1gMNqWF8RKmbvwQjT4/xTvdFCJpLBZZJJF6s=
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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