reallocarray(3) is not in POSIX thus not visible with _POSIX_C_SOURCE. Linux cheats POSIX via _DEFAULT_SOURCE but on BSDs the cheat knob is different (__BSD_VISIBLE on DragonFly/FreeBSD/OpenBSD and _NETBSD_SOURCE on NetBSD).
$ cc --version
FreeBSD clang version 15.0.6 (https://github.com/llvm/llvm-project.git llvmorg-15.0.6-0-g088f33605d8a)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin
$ meson setup _build
$ meson compile -C _build
[...]
../cagebreak.c:197:11: warning: call to undeclared function 'reallocarray'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
line = reallocarray(line, line_length, sizeof(char));
^
../cagebreak.c:197:9: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
line = reallocarray(line, line_length, sizeof(char));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note, on Clang < 15 -Wint-conversion doesn't error out, so the implicit declaration of reallocarray sometimes leads to crashes.
reallocarray(3) is not in POSIX thus not visible with
_POSIX_C_SOURCE
. Linux cheats POSIX via_DEFAULT_SOURCE
but on BSDs the cheat knob is different (__BSD_VISIBLE
on DragonFly/FreeBSD/OpenBSD and_NETBSD_SOURCE
on NetBSD).Note, on Clang < 15
-Wint-conversion
doesn't error out, so the implicit declaration ofreallocarray
sometimes leads to crashes.