From dc0fd4723907775bdfc3ffb2a612a04d60789ed8 Mon Sep 17 00:00:00 2001 From: Rudi Heitbaum Date: Wed, 22 May 2024 22:04:56 +1000 Subject: [PATCH 1/2] vclog: fix max realloc compiler error Fixes ./vclog/vclog.c:211:34: error: argument 2 value '4294967288' exceeds maximum object size 2147483647 [-Werror=alloc-size-larger-than=] 211 | payload_buffer = realloc(payload_buffer, payload_buffer_size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ./vclog/vclog.c:17: ../../toolchain/armv7ve-libreelec-linux-gnueabihf/sysroot/usr/include/stdlib.h:683:14: note: in a call to allocation function 'realloc' declared here 683 | extern void *realloc (void *__ptr, size_t __size) | ^~~~~~~ --- vclog/vclog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vclog/vclog.c b/vclog/vclog.c index 85e1366..24e2b1e 100644 --- a/vclog/vclog.c +++ b/vclog/vclog.c @@ -72,6 +72,7 @@ enum }; #define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define ARRAY_SIZE(_a) (sizeof(_a)/sizeof(_a[0])) #define FBIODMACOPY _IOW('z', 0x22, struct fb_dmacopy) @@ -207,7 +208,7 @@ int32_t main(int32_t argc, char *argv[]) if (payload_len > payload_buffer_size) { payload_buffer_size = MAX(payload_len, 100); // skip some churn - payload_buffer = realloc(payload_buffer, payload_buffer_size); + payload_buffer = realloc(payload_buffer, MIN(INT32_MAX, payload_buffer_size)); if (!payload_buffer) die("Out of memory"); } From 94977ce239cef302f2b3f41eefb228d6cb2e6313 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 23 May 2024 11:42:20 +0100 Subject: [PATCH 2/2] squash: An alternative fix --- vclog/vclog.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vclog/vclog.c b/vclog/vclog.c index 24e2b1e..5f2c981 100644 --- a/vclog/vclog.c +++ b/vclog/vclog.c @@ -72,7 +72,6 @@ enum }; #define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define ARRAY_SIZE(_a) (sizeof(_a)/sizeof(_a[0])) #define FBIODMACOPY _IOW('z', 0x22, struct fb_dmacopy) @@ -119,7 +118,7 @@ int32_t main(int32_t argc, char *argv[]) uint32_t logs_start_vc = 0; uint32_t logs_size = 0; char *payload_buffer = NULL; - uint32_t payload_buffer_size = 0; + size_t payload_buffer_size = 0; uint32_t log_id; uint32_t log_addr; uint32_t log_size; @@ -208,7 +207,7 @@ int32_t main(int32_t argc, char *argv[]) if (payload_len > payload_buffer_size) { payload_buffer_size = MAX(payload_len, 100); // skip some churn - payload_buffer = realloc(payload_buffer, MIN(INT32_MAX, payload_buffer_size)); + payload_buffer = realloc(payload_buffer, payload_buffer_size); if (!payload_buffer) die("Out of memory"); }