]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
lib: Add static inline reallocarray fallback function
authorMark Wielaard <mark@klomp.org>
Wed, 28 Jul 2021 14:46:36 +0000 (16:46 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 29 Jul 2021 12:08:45 +0000 (14:08 +0200)
Signed-off-by: Mark Wielaard <mark@klomp.org>
ChangeLog
configure.ac
lib/ChangeLog
lib/system.h

index a01f6f9fb4d42d21a06e3bf38c8c9dffe2e5d8c0..12b8f403816bf7ec883b8a69a2d0827ad2e98905 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index b348a7176709117990c5a7985d9865594b7770c9..7caff2c581be6f8038e10b19b6f0b93624c9414e 100644 (file)
@@ -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])
 
index dd3ebcab90cb9f4907736696ec1189366f0e4f36..44366fec9b91ca302599489521e995913769d9a3 100644 (file)
@@ -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.
index cdf18ed736a9b076335128153a0b2860a5ebf98d..58d9deee638f615c3241f4be0e5620ec64d78056 100644 (file)
@@ -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)
     ((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