diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | lib/ChangeLog | 4 | ||||
-rw-r--r-- | lib/system.h | 14 |
4 files changed, 25 insertions, 0 deletions
@@ -1,3 +1,7 @@ +2021-07-28 Mark Wielaard <mark@klomp.org> + + * configure.ac (AC_CHECK_DECLS): Add reallocarray check. + 2021-05-22 Mark Wielaard <mark@klomp.org> * configure.ac (AC_INIT): Set version to 0.185. diff --git a/configure.ac b/configure.ac index b348a717..7caff2c5 100644 --- a/configure.ac +++ b/configure.ac @@ -425,6 +425,9 @@ AC_CHECK_DECLS([powerof2],[],[],[#include <sys/param.h>]) AC_CHECK_DECLS([mempcpy],[],[], [#define _GNU_SOURCE #include <string.h>]) +AC_CHECK_DECLS([reallocarray],[],[], + [#define _GNU_SOURCE + #include <stdlib.h>]) AC_CHECK_FUNCS([process_vm_readv]) diff --git a/lib/ChangeLog b/lib/ChangeLog index dd3ebcab..44366fec 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2021-07-28 Mark Wielaard <mark@klomp.org> + + * system.h (reallocarray): New static inline fallback function. + 2021-04-19 Martin Liska <mliska@suse.cz> * system.h (startswith): New function. diff --git a/lib/system.h b/lib/system.h index cdf18ed7..58d9deee 100644 --- a/lib/system.h +++ b/lib/system.h @@ -38,6 +38,7 @@ #include <byteswap.h> #include <unistd.h> #include <string.h> +#include <stdlib.h> #if __BYTE_ORDER == __LITTLE_ENDIAN # define LE32(n) (n) @@ -70,6 +71,19 @@ ((void *) ((char *) memcpy (dest, src, n) + (size_t) n)) #endif +#if !HAVE_DECL_REALLOCARRAY +static inline void * +reallocarray (void *ptr, size_t nmemb, size_t size) +{ + if (size > 0 && nmemb > SIZE_MAX / size) + { + errno = ENOMEM; + return NULL; + } + return realloc (ptr, nmemb * size); +} +#endif + /* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */ static inline int |