From d51b1d3cb936c8390a34ed87d81303efbb7df533 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sat, 25 Oct 2014 13:45:05 -0400 Subject: src/shared/util.h: import realloc_multiply() from upstream Signed-off-by: Anthony G. Basile --- src/shared/strv.h | 2 +- src/shared/util.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 #include -#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. */ -- cgit v1.2.3-54-g00ecf