summaryrefslogtreecommitdiff
path: root/lib/malloca.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-04-25 18:24:42 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-04-25 18:25:31 -0700
commit974ddbe54c37dd1f8f0f0f11f6f967d6fecd864d (patch)
tree7b106c0d4f17a403adefeaee5fd8f50494731030 /lib/malloca.h
parentffdf094f83481d04c58fc36fc7a32ba440f365c7 (diff)
downloadgnulib-974ddbe54c37dd1f8f0f0f11f6f967d6fecd864d.tar.gz
reallocarray: don’t crash if item size is 0
This problem affects only platforms where xalloc_oversized divides a number by the size arg. Fix this by defining xalloc_oversized (n, s) to work even if s == 0. * lib/malloca.h, lib/xalloc-oversized.h: Document new behavior. * lib/xalloc-oversized.h (__xalloc_oversized): Do not crash if S==0. * tests/test-reallocarray.c (main): Test for the bug.
Diffstat (limited to 'lib/malloca.h')
-rw-r--r--lib/malloca.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/malloca.h b/lib/malloca.h
index a255e3f04b..d646d41028 100644
--- a/lib/malloca.h
+++ b/lib/malloca.h
@@ -76,7 +76,7 @@ extern void freea (void *p);
/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
It allocates an array of N objects, each with S bytes of memory,
- on the stack. S must be positive and N must be nonnegative.
+ on the stack. N and S should be nonnegative and free of side effects.
The array must be freed using freea() before the function returns. */
#define nmalloca(n, s) \
(xalloc_oversized (n, s) ? NULL : malloca ((n) * (size_t) (s)))