diff options
-rw-r--r-- | src/shared/strv.h | 2 | ||||
-rw-r--r-- | src/shared/util.h | 7 |
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. */ |