From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id E0315385842C for ; Thu, 2 Mar 2023 14:57:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0315385842C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x234.google.com with SMTP id r40so12712368oiw.0 for ; Thu, 02 Mar 2023 06:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677769062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Sw6KlHDXk+1AKI/A8djRfwpZG1sVZfrQeAMWlQbOlDA=; b=OWM2/sA6ogGFAsSFaxcTlOz80wuFqvj4vLIbjfvNE+RQvOLtLyActlIkyvXTR0aDfo hHQdi/wSScccMAVhucZeEi2oiKU4eWG39PzhdxL72AIHCcyfsj/38xF4gz7pkcxPjT4z rwtcfWwS/zoEbOcPKRGwrI1ehvbBnfC5X8uRCiceZc7luZefeW3raUVAPsEYRAcnr+AU 1ZrxNplJXPBZLLZmwBZyLBA+BmpwN69JTvrlWGq+uIJEMImT/FL+J6S6wGUdSDuY7lhE DfLmWTUdj4YHZN3gHGTOBTDc7q+JIagtbEaPEGzJKuTjJXn7IJM+DYDIjONnfQ23Th01 ogkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677769062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sw6KlHDXk+1AKI/A8djRfwpZG1sVZfrQeAMWlQbOlDA=; b=wx7I9Y2pXsj/b8D+5ahyYTG8+G5DuknYQGFLKC2GK1lZAEhyO65q6/Q3lZCJTZKPMU T66SDQKk6HQuo4/nZiY1IJR4qqQuClueUw65X3Ba6KcwPQNgrDpfQBQ9uPeW6m81/8v0 sWg45OZj4Vrok0ehGN/VVPPdFYRRLhUqMgwKEbhY8RWK1ahVbrbXXFSkgIShEiRrX5In V4X4W5lfnv4pGUB03Cc/G/4t7ci4hy2v347AMtHcmYWzYpL25kvjdixVWIOYpQo3cDm8 xGJSwnb0ttwl8WD6t5m1afFjB0UhzqXlK96TKLQY7yYfcvt88EkcXlaV+T1hZJDnP6Bl 8iUQ== X-Gm-Message-State: AO0yUKXN3hP+nDX9buQY648vkmMDkHDrHVEJwzh0MuyOJmYwBCFy2XM3 MgmlWO7Y0OMrEKh6+mGNaLGkMM2AhKLNuxJO+iQ= X-Google-Smtp-Source: AK7set8au0ZCNKBUQKTou0hRJ2zHvn9Y+mFYpzvM4i1k8qbOY9ri1OR4CHwnM0G7zp1Xo6zvo6JpYw== X-Received: by 2002:a05:6808:3c7:b0:384:ec1:cc6c with SMTP id o7-20020a05680803c700b003840ec1cc6cmr5334564oie.54.1677769061503; Thu, 02 Mar 2023 06:57:41 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:953:d4b:62c6:5aa0]) by smtp.gmail.com with ESMTPSA id t26-20020a056808159a00b00383cc29d6b2sm7001652oiw.51.2023.03.02.06.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 06:57:40 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, "Andreas K . Huettel" , Paul Eggert , Florian Weimer Subject: [PATCH v6 2/3] support: Add xreallocarray Date: Thu, 2 Mar 2023 11:57:31 -0300 Message-Id: <20230302145732.2293756-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302145732.2293756-1-adhemerval.zanella@linaro.org> References: <20230302145732.2293756-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: As a wrapper over reallocarray. --- support/Makefile | 1 + support/support.h | 2 ++ support/xreallocarray.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 support/xreallocarray.c diff --git a/support/Makefile b/support/Makefile index a304c5cdc0..1ca4a9567e 100644 --- a/support/Makefile +++ b/support/Makefile @@ -191,6 +191,7 @@ libsupport-routines = \ xraise \ xreadlink \ xrealloc \ + xreallocarray \ xrecvfrom \ xsendto \ xsetlocale \ diff --git a/support/support.h b/support/support.h index 525ff1ebce..741e4c5c2a 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..6478725c9c --- /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) + oom_error ("reallocarray", n); + return r; +} -- 2.34.1