Skip to content

vclog: fix max realloc compiler error - #88

Merged
pelwell merged 3 commits into
raspberrypi:masterfrom
heitbaum:patch-2
Nov 13, 2026
Merged

pelwell merged 3 commits into
raspberrypi:masterfrom
heitbaum:patch-2

Conversation

@heitbaum

Copy link
Copy Markdown
Contributor

./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)
| ^~~~~~~

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)
      |              ^~~~~~~
@pelwell

pelwell commented May 23, 2024

Copy link
Copy Markdown
Collaborator

Does this follow-up patch (which should be in heitbaum:patch-2 now) also work? It looks more correct to me.

@heitbaum

Copy link
Copy Markdown
Contributor Author

Does this follow-up patch (which should be in heitbaum:patch-2 now) also work? It looks more correct to me.

I didn’t like my version of 88 either (which is why I separated it from 87) but the size_t doesn’t work either. It matches 4GB too.

FAILED: vclog/CMakeFiles/vclog.dir/vclog.c.o 
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/bin/armv7ve-libreelec-linux-gnueabihf-gcc   -march=armv7ve -mtune=cortex-a7 -mabi=aapcs-linux -Wno-psabi -Wa,-mno-warn-deprecated -mfloat-abi=hard -mfpu=neon-vfpv4 -Wall -pipe  -O2 -fomit-frame-pointer -DNDEBUG -Wall -Wextra -Werror -pedantic -DDUMMYOPT -MD -MT vclog/CMakeFiles/vclog.dir/vclog.c.o -MF vclog/CMakeFiles/vclog.dir/vclog.c.o.d -o vclog/CMakeFiles/vclog.dir/vclog.c.o -c /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/bcm2835-utils-6dc6f5f3d129a6c9423316ac1a53efb19a5c40d1/vclog/vclog.c
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/bcm2835-utils-6dc6f5f3d129a6c9423316ac1a53efb19a5c40d1/vclog/vclog.c: In function 'main':
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/bcm2835-utils-6dc6f5f3d129a6c9423316ac1a53efb19a5c40d1/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 /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/bcm2835-utils-6dc6f5f3d129a6c9423316ac1a53efb19a5c40d1/vclog/vclog.c:17:
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/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)
      |              ^~~~~~~
cc1: all warnings being treated as errors

@stintel

stintel commented Oct 24, 2025

Copy link
Copy Markdown

Hitting this problem in OpenWrt master while building for Raspberry Pi Zero W. @heitbaum's fix (dc0fd47) works. Adding @pelwell's follow-up patch (94977ce) breaks things again.

If log_copy_wrap copies nothing, msg.size stays 0 and payload_len
wraps to 0xfffffff8. The payload_len > log_size check can't exclude
that at compile time, so 32-bit ARM gcc 14 at -O3 fails with:

  error: argument 2 value '4294967288' exceeds maximum object size
  2147483647 [-Werror=alloc-size-larger-than=]

Treat msg.size < sizeof(msg_hdr_t) as corruption, which also bounds
payload_len to 16 bits. Revert the size_t change, which did not help
on 32-bit targets.

Signed-off-by: Dom Cobley <[email protected]>
@popcornmix

Copy link
Copy Markdown
Contributor

I've pushed 5c5e2fd, which replaces both earlier attempts.

Cause: if log_copy_wrap() returns early (offset >= log_size), nothing is copied, msg.size stays 0 (from the msg.size = 0 added in b9c6321) and payload_len = 0 - sizeof(msg_hdr_t) = 0xfffffff8. The existing payload_len > log_size check can't rule that out at compile time, since log_size is only known at run time, so gcc sees a path where realloc() is passed 4294967288.

First version (MIN(INT32_MAX, payload_buffer_size)): silences the warning, but payload_buffer_size can then be larger than the buffer actually allocated, so a later copy of payload_len bytes could overflow it. It hides the problem rather than fixing it.

Second version (size_t payload_buffer_size): on 32-bit targets size_t is still 32 bits, so the value is unchanged and the error remains (as reported above).

This version: treats msg.size < sizeof(msg_hdr_t) as a corrupt entry. That removes the wrapped value and, as msg.size is a uint16_t, limits payload_len to under 64 KiB. The net change of the PR is now:

-            if (payload_len > log_size)
+            if (msg.size < sizeof(msg_hdr_t) || payload_len > log_size)

Testing: the error only shows with 32-bit ARM gcc 14/15 at -O3. It doesn't appear at -O2/-Os, on arm64 (gcc 14.2) or on x86 (-m32/-m64, gcc 14.2). Using ARM gcc 14.1 and 15.2 on godbolt with -march=armv7ve -mfloat-abi=hard -mfpu=neon-vfpv4 -Wall -Wextra -Werror -pedantic:

Version -O3
current master error
size_t version error
MIN(INT32_MAX, ...) version builds
this PR (5c5e2fd) builds
this PR merged with current master (gcc 14.1) builds

This PR, alone and merged with current master, also builds clean at -O2 and -Os (ARM gcc 14.1). It merges into master without conflicts.

@popcornmix

Copy link
Copy Markdown
Contributor

@pelwell okay with this version? It will want a "squash and merge".

@pelwell
pelwell merged commit ac6422e into raspberrypi:master Nov 13, 2026
4 checks passed
@heitbaum
heitbaum deleted the patch-2 branch November 13, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile error with gcc-14.1 and 32-bit / 64-bit targets

4 participants