rs: fix darwin

This commit is contained in:
Stanisław Pitucha 2024-04-15 10:18:00 +10:00
parent 1f54fa2ddf
commit 057c8ca96d
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,26 @@
Original from OpenBSD src/lib/libc/stdlib/reallocarray.c
--- a/rs.c 2024-04-15 10:13:41
+++ b/rs.c 2024-04-15 10:15:20
@@ -103,6 +103,21 @@
ep = getptrs(ep); \
} while(0)
+#ifdef __APPLE__
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
+#endif
+
int
main(int argc, char *argv[])
{

View File

@ -16,6 +16,11 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ installShellFiles ];
patches = [
# add an implementation of reallocarray() from openbsd (not available on darwin)
./macos-reallocarray.patch
];
buildInputs = [ libbsd ];
buildPhase = ''
@ -63,5 +68,6 @@ stdenv.mkDerivation rec {
license = licenses.bsd3;
maintainers = with maintainers; [ AndersonTorres ];
platforms = platforms.unix;
broken = stdenv.isx86_64 && stdenv.isDarwin; # missing strtonum()
};
}