summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2014-10-25 13:45:05 -0400
committerAnthony G. Basile <blueness@gentoo.org>2014-10-25 13:45:05 -0400
commitd51b1d3cb936c8390a34ed87d81303efbb7df533 (patch)
tree92df64b74d6eb98203fba5173ba0d0a21e29bcde /src/shared
parent1b6c7e7255cf5d03d049f63dfdea24f6f64328d1 (diff)
src/shared/util.h: import realloc_multiply() from upstream
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/strv.h2
-rw-r--r--src/shared/util.h7
2 files changed, 8 insertions, 1 deletions
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 6e0c7655d9..22c8132c57 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -22,7 +22,7 @@
#include <stdarg.h>
#include <stdbool.h>
-#include "macro.h"
+#include "util.h"
void strv_free(char **l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free);
diff --git a/src/shared/util.h b/src/shared/util.h
index 60ea971dc3..805cf29920 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -341,6 +341,13 @@ _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b)
return malloc(a * b);
}
+_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) {
+ if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
+ return NULL;
+
+ return realloc(p, a * b);
+}
+
/**
* Check if a string contains any glob patterns.
*/