From de6894e291369f73dc343d544b29367493b312b4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 19 Oct 2021 16:31:32 -0700 Subject: [PATCH] xalloc: new function xinmalloc * lib/xmalloc.c (xinmalloc): New function, which is like xnmalloc but for idx_t instead of size_t. --- ChangeLog | 6 ++++++ lib/xalloc.h | 3 +++ lib/xmalloc.c | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index a017453dc..2f19e30a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-10-19 Paul Eggert + + xalloc: new function xinmalloc + * lib/xmalloc.c (xinmalloc): New function, which is like + xnmalloc but for idx_t instead of size_t. + 2021-10-18 Paul Eggert regex: fix buffer read overrrun diff --git a/lib/xalloc.h b/lib/xalloc.h index ee07113fe..7f2c3fb8a 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -60,6 +60,9 @@ void *xmalloc (size_t s) void *ximalloc (idx_t s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL; +void *xinmalloc (idx_t n, idx_t s) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE + _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL; void *xzalloc (size_t s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL; diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 51a0832de..d5def0bc7 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -101,6 +101,12 @@ xnmalloc (size_t n, size_t s) return xreallocarray (NULL, n, s); } +void * +xinmalloc (idx_t n, idx_t s) +{ + return xireallocarray (NULL, n, s); +} + /* If P is null, allocate a block of at least *PS bytes; otherwise, reallocate P so that it contains more than *PS bytes. *PS must be nonzero unless P is null. Set *PS to the new block's size, and -- 2.31.1