diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-04-18 16:24:51 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-04-18 20:59:51 -0700 |
commit | 109f6d1f8c520a0c2cfeee940a9671c83361a8c1 (patch) | |
tree | 852af133949935928ff7d87daff059684c755c3c /lib/xmalloc.c | |
parent | 9fd0a1ded22094060e351c4df9a1f2448af5eeaf (diff) | |
download | gnulib-109f6d1f8c520a0c2cfeee940a9671c83361a8c1.tar.gz |
xalloc: new function xreallocarray
This effectively replaces xnmalloc, which perhaps should be deprecated.
The name xreallocarray should be easier to remember now that
reallocarray is a standard GNU function.
* lib/xalloc.h [GNULIB_XALLOC]: Do not include xalloc-oversized.h.
(xnmalloc, xnrealloc, x2nrealloc): Simplify by using xreallocarray.
* lib/xmalloc.c (xreallocarray): New function.
* modules/xalloc (Depends-on): Add reallocarray;
remove xalloc-oversized.
Diffstat (limited to 'lib/xmalloc.c')
-rw-r--r-- | lib/xmalloc.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 39ce893ad3..88698fadef 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -50,6 +50,18 @@ xrealloc (void *p, size_t n) return r; } +/* Change the size of an allocated block of memory P to an array of N + objects each of S bytes, with error checking. */ + +void * +xreallocarray (void *p, size_t n, size_t s) +{ + void *r = reallocarray (p, n, s); + if (!r && (!p || (n && s))) + xalloc_die (); + return r; +} + /* If P is null, allocate a block of at least *PN bytes; otherwise, reallocate P so that it contains more than *PN bytes. *PN must be nonzero unless P is null. Set *PN to the new block's size, and |