X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmalloca.h;h=5bb2d47348438109a962e64471e01a70f1815cda;hb=1a2869593e115e4a6c74aaa0b23ca612357403ce;hp=2f74b9617012850dff8bc9e126c3b3d927079e2f;hpb=6418675e9be058535f73e5fabfc8085f4fdd08b1;p=gnulib.git diff --git a/lib/malloca.h b/lib/malloca.h index 2f74b9617..5bb2d4734 100644 --- a/lib/malloca.h +++ b/lib/malloca.h @@ -70,9 +70,19 @@ extern void freea (void *p); # define freea free #endif -/* Maybe we should also define a variant - nmalloca (size_t n, size_t s) - behaves like malloca (n * s) - If this would be useful in your application. please speak up. */ +/* 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. + The array must be freed using freea() before the function returns. */ +#if 1 +/* Cf. the definition of xalloc_oversized. */ +# define nmalloca(n, s) \ + ((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \ + ? NULL \ + : malloca ((n) * (s))) +#else +extern void * nmalloca (size_t n, size_t s); +#endif #ifdef __cplusplus