summaryrefslogtreecommitdiff
path: root/portable/reallocarray.c
diff options
context:
space:
mode:
Diffstat (limited to 'portable/reallocarray.c')
-rw-r--r--portable/reallocarray.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/portable/reallocarray.c b/portable/reallocarray.c
index e9404e9..3c6ea37 100644
--- a/portable/reallocarray.c
+++ b/portable/reallocarray.c
@@ -7,17 +7,19 @@
* and checks for overflow so that the caller doesn't need to.
*
* The canonical version of this file is maintained in the rra-c-util package,
- * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014
+ * The Board of Trustees of the Leland Stanford Junior University
*
- * The authors hereby relinquish any claim to any copyright that they may have
- * in this work, whether granted under contract or by operation of law or
- * international treaty, and hereby commit to the public, at large, that they
- * shall not, at any time in the future, seek to enforce any copyright in this
- * work against any person or entity, or prevent any person or entity from
- * copying, publishing, distributing or creating derivative works of this
- * work.
+ * Copying and distribution of this file, with or without modification, are
+ * permitted in any medium without royalty provided the copyright notice and
+ * this notice are preserved. This file is offered as-is, without any
+ * warranty.
+ *
+ * SPDX-License-Identifier: FSFAP
*/
#include <config.h>
@@ -52,5 +54,11 @@ reallocarray(void *ptr, size_t nmemb, size_t size)
errno = ENOMEM;
return NULL;
}
+
+ /* Avoid a zero-size allocation. */
+ if (nmemb == 0 || size == 0) {
+ nmemb = 1;
+ size = 1;
+ }
return realloc(ptr, nmemb * size);
}