From patchwork Thu Mar 2 14:57:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 65904 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C33E3857026 for ; Thu, 2 Mar 2023 14:58:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C33E3857026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677769087; bh=Sw6KlHDXk+1AKI/A8djRfwpZG1sVZfrQeAMWlQbOlDA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jDrI4XH6u/kaHhL+WqP0orBdyPYsGJ2w8RCFKQKw9os+nmUwQDGo0YC6OroWCGUYP F4E+7j+OOvmtljTyEt/zhKEORJIj7gJOVEtEXyj7QDv+Zl8DU3TMYR0OXbjjcUX1ar pVIRXJiCJS37PEfyoMSy6sVRLDv25ZFLKMFJ5V54= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 Received: by mail-oi1-x234.google.com with SMTP id r40so12712368oiw.0 for ; Thu, 02 Mar 2023 06:57:42 -0800 (PST) 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) 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 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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; +}