aboutsummaryrefslogtreecommitdiff
path: root/malloc/dynarray_resize.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-08-30 20:10:56 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-08-30 20:10:56 +0200
commit5898f4548efdcd7c0fd437a74eeb80facc51a117 (patch)
tree3388b5acb0e092a716110ba3cfe176b01d3e72d8 /malloc/dynarray_resize.c
parenta9da0bb2667ab20f1dbcd0a9ae6846db02fbc96a (diff)
downloadglibc-5898f4548efdcd7c0fd437a74eeb80facc51a117.tar
glibc-5898f4548efdcd7c0fd437a74eeb80facc51a117.tar.gz
glibc-5898f4548efdcd7c0fd437a74eeb80facc51a117.tar.bz2
glibc-5898f4548efdcd7c0fd437a74eeb80facc51a117.zip
dynarray: Set errno on overflow-induced allocation failure
This allows the caller to return directly on such an error, with an appropriate errno value.
Diffstat (limited to 'malloc/dynarray_resize.c')
-rw-r--r--malloc/dynarray_resize.c7
1 files changed, 6 insertions, 1 deletions
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 @@
<http://www.gnu.org/licenses/>. */
#include <dynarray.h>
+#include <errno.h>
#include <malloc-internal.h>
#include <stdlib.h>
#include <string.h>
@@ -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)
{