From 5898f4548efdcd7c0fd437a74eeb80facc51a117 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 30 Aug 2017 20:10:56 +0200 Subject: dynarray: Set errno on overflow-induced allocation failure This allows the caller to return directly on such an error, with an appropriate errno value. --- malloc/dynarray_resize.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'malloc/dynarray_resize.c') diff --git a/malloc/dynarray_resize.c b/malloc/dynarray_resize.c index e6dc9fbc68..63c981bf61 100644 --- a/malloc/dynarray_resize.c +++ b/malloc/dynarray_resize.c @@ -17,6 +17,7 @@ . */ #include +#include #include #include #include @@ -38,7 +39,11 @@ __libc_dynarray_resize (struct dynarray_header *list, size_t size, size_t new_size_bytes; if (check_mul_overflow_size_t (size, element_size, &new_size_bytes)) - return false; + { + /* Overflow. */ + __set_errno (ENOMEM); + return false; + } void *new_array; if (list->array == scratch) { -- cgit v1.2.3