icoutils/0025-wrestool-fileread-Fix-check_offset-to-be-const-corre.patch
Richard W.M. Jones 86a1ed311e Add a series of upstream patches to enable compiler warnings and
fix multiple issues.

Revert one of the checks which breaks processing of PE binaries.

Removed the 'Group' line, not needed with modern Fedora/RPM.
2017-03-10 12:18:04 +00:00

59 lines
1.7 KiB
Diff

From da334f5a8754e164e53686c9399e797f124ba034 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 9 Mar 2017 15:12:16 +0000
Subject: [PATCH 25/26] wrestool/fileread: Fix check_offset to be const-correct
and use size_t.
Three things were wrong with this function:
(1) Always use size_t when calculating or storing the size of an
object in memory.
(2) The function wasn't const-correct.
(3) The function use arithmetic operations on void* pointers (which is
not defined in C).
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
wrestool/fileread.c | 9 +++++----
wrestool/fileread.h | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/wrestool/fileread.c b/wrestool/fileread.c
index 0ec7c49..cb0d7a0 100644
--- a/wrestool/fileread.c
+++ b/wrestool/fileread.c
@@ -33,11 +33,12 @@
* Usually not called directly.
*/
bool
-check_offset(char *memory, int total_size, char *name, void *offset, int size)
+check_offset(const char *memory, size_t total_size,
+ const char *name, const void *offset, size_t size)
{
- char* memory_end = memory + total_size;
- char* block = (char*)offset;
- char* block_end = offset + size;
+ const char* memory_end = memory + total_size;
+ const char* block = (const char*) offset;
+ const char* block_end = block + size;
/*debug("check_offset: size=%x vs %x offset=%x size=%x\n",
need_size, total_size, (char *) offset - memory, size);*/
diff --git a/wrestool/fileread.h b/wrestool/fileread.h
index 1cc7358..45ea543 100644
--- a/wrestool/fileread.h
+++ b/wrestool/fileread.h
@@ -33,6 +33,6 @@
return (r); \
}
-bool check_offset(char *, int, char *, void *, int);
+bool check_offset(const char *, size_t, const char *, const void *, size_t);
#endif
--
2.10.2