diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-02-10 11:29:12 -0500 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-02-10 11:29:12 -0500 |
commit | ec831d9055a20b69cb9a7300990b8e4414cbd474 (patch) | |
tree | 2ad72d41955388fbb826a51500eb6bad89303708 /pw/reallocarray.c | |
parent | 66124b92b65dcc15b9695c7e05d72c7c7e174c39 (diff) | |
download | pw-darwin-ec831d9055a20b69cb9a7300990b8e4414cbd474.tar.gz pw-darwin-ec831d9055a20b69cb9a7300990b8e4414cbd474.tar.zst pw-darwin-ec831d9055a20b69cb9a7300990b8e4414cbd474.zip |
pw: fix building for iOS, completely untested
Diffstat (limited to 'pw/reallocarray.c')
-rw-r--r-- | pw/reallocarray.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pw/reallocarray.c b/pw/reallocarray.c new file mode 100644 index 0000000..7310133 --- /dev/null +++ b/pw/reallocarray.c @@ -0,0 +1,11 @@ +#include "reallocarray.h" + +#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); +} |