From patchwork Mon Mar 13 19:34:18 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: 66316 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 6D447385559F for ; Mon, 13 Mar 2023 19:34:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D447385559F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678736096; bh=q8bJLcInGYvtNiIzwDvtwXgEzHeWRGSONn+az+ZAKPo=; 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=ZXNgtrtzZ3Bm/ohIFD6iqkvlq+1RgFpjRQrvo/OP//5rWFq2cuogGo/NeNicVh7F4 QYPvVjfHsGKPTPg10juYksRFVO9Gxh0aDyKphCLeXC4WtmGwgBHFwWouugBxTRI1i7 erG5J3MDxQ4sHPb7Lk5Bq4e6jLSOGubeXK27qf28= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id B4BDA3858D39 for ; Mon, 13 Mar 2023 19:34:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4BDA3858D39 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-176261d7f45so14891441fac.11 for ; Mon, 13 Mar 2023 12:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678736068; 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=q8bJLcInGYvtNiIzwDvtwXgEzHeWRGSONn+az+ZAKPo=; b=iIaN8iHsoJeyXnjALBhUjbQC54FQSlxXWoK5ilIAlu39OvPUyvqgkkT5eP8ECIB/oF f4/Kuo8Ydi32P6S1mTqdNgEN2u9YBCDdZzxqzyjNT4PNogCk095SHcJuAdyv3m3CCmd5 zw1783iauLtDkQV0aJx/C8EuOA8oSOqHeVi/mNoeB7JmTzjXw1ukvgNyepmQaBRMDxRH 6+FDE59bdaumOA1ghL0TrhX/EZ88WP5kaQ2REXN4bFLE4U0cbB98PIQYfvpJRKlrztl6 6BR2N0/EDLT0x9L8x03SuAFnb70OnUlTFS/WP/B3/diNauuBWGqXJBQHXcemEEAT91BU 4Rjw== X-Gm-Message-State: AO0yUKVjKonFt94s8JRoyoaohEGEtI/shE3QFG0Dq5k7Qyy3LTohiMdv p+gjYLKaj2cPx/QBWbeMPG06O3UZU7x9+SuLDVpsJA== X-Google-Smtp-Source: AK7set/y1X4me82N9Zkj6y8qdzUUh/+tbKPKTMzRb+vDwM1CY56fRRd1XaLrnK5w8HMnkZK3asd/tA== X-Received: by 2002:a05:6870:12d0:b0:17a:a29d:aa96 with SMTP id 16-20020a05687012d000b0017aa29daa96mr319020oam.57.1678736068465; Mon, 13 Mar 2023 12:34:28 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:544b:9bad:e673:fbfa:30eb]) by smtp.gmail.com with ESMTPSA id zf9-20020a0568716a8900b00172426ebe58sm325724oab.27.2023.03.13.12.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 12:34:27 -0700 (PDT) To: libc-alpha@sourceware.org, "Andreas K . Huettel" , Paul Eggert , Florian Weimer Subject: [PATCH v7 2/3] support: Add xreallocarray Date: Mon, 13 Mar 2023 16:34:18 -0300 Message-Id: <20230313193419.36985-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313193419.36985-1-adhemerval.zanella@linaro.org> References: <20230313193419.36985-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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 05b31159ea..461247827d 100644 --- a/support/Makefile +++ b/support/Makefile @@ -194,6 +194,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..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; +}