From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 237B03858C60; Fri, 29 Dec 2023 19:59:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 237B03858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1703879987; bh=9CeaSyarb0eu8JZnFoUCiFRmSeUqW0JB6x13CZXOSic=; h=From:To:Subject:Date:From; b=qzHgiy1Zi2nDCSzqZX5NEwY1YwFaOJgJOsPm9y/cToj3oKg2ijvLPNYsvvNJe2EJH yAAchJTrRsETuXMz2Z/bxEJy05QvVE2E4v+b/A1m29UusDUJesnbwJC2q5NcDOE+PY uqHH8VSZ6DIkaawgBPo2+pvjE19oM96d0qlOU0vo= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/bz23960-dirent] support: Add xreallocarray X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/bz23960-dirent X-Git-Oldrev: 396cc2c088afbf3846c54f6195fa98fa06d23e21 X-Git-Newrev: 5c2728e451fa15b97b5161ffd20cf647b54f39e6 Message-Id: <20231229195947.237B03858C60@sourceware.org> Date: Fri, 29 Dec 2023 19:59:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5c2728e451fa15b97b5161ffd20cf647b54f39e6 commit 5c2728e451fa15b97b5161ffd20cf647b54f39e6 Author: Adhemerval Zanella Date: Wed Mar 1 14:41:23 2023 -0300 support: Add xreallocarray As a wrapper over reallocarray. Diff: --- support/Makefile | 1 + support/support.h | 2 ++ support/xreallocarray.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/support/Makefile b/support/Makefile index 9aa7f23a6e..25233bcf8f 100644 --- a/support/Makefile +++ b/support/Makefile @@ -201,6 +201,7 @@ libsupport-routines = \ xread \ xreadlink \ xrealloc \ + xreallocarray \ xrecvfrom \ xsendto \ xsetlocale \ diff --git a/support/support.h b/support/support.h index 4a068d3aee..31cea1df17 100644 --- a/support/support.h +++ b/support/support.h @@ -107,6 +107,8 @@ extern void *xcalloc (size_t n, size_t s) __returns_nonnull; extern void *xrealloc (void *o, size_t n) __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free; +extern void *xreallocarray (void *p, size_t n, size_t s) + __attribute_alloc_size__ ((2, 3)) __attr_dealloc_free; extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free __returns_nonnull; void *xposix_memalign (size_t alignment, size_t n) diff --git a/support/xreallocarray.c b/support/xreallocarray.c new file mode 100644 index 0000000000..74fdaa421b --- /dev/null +++ b/support/xreallocarray.c @@ -0,0 +1,29 @@ +/* Error-checking wrapper for reallocarray + Copyright (C) 2016-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +void * +xreallocarray (void *p, size_t n, size_t s) +{ + void *r = reallocarray (p, n, s); + if (r == NULL && (p == NULL || (n != 0 && s != 0))) + oom_error ("reallocarray", n); + return r; +}