From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-oa1-x2b.google.com with SMTP id 586e51a60fabf-176261d7f45so14891441fac.11 for ; Mon, 13 Mar 2023 12:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678736068; 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=q8bJLcInGYvtNiIzwDvtwXgEzHeWRGSONn+az+ZAKPo=; b=n5BQyb8s0boC8s9YhYtv2b4Xo56Ukicg2Ll7P9tm0FWqQq6XS9u4JNvI207/Qi1RkJ +PRky4ch/3zLPlhxqLlEAcXDsn5QmUZ6+KC5sRLGv020D/XCzaufJ8c5dl22tCz3sDmK SnARTjal5q7/sPB1BpgOLLkAdEV11lZKISPbkeLiPMaXzwvJXWhhZNjum90UUeBAHFz5 ZwTXnGfMrd6JGfKtOXkRb38Ym7jvSBg2lUhv9makal6HIaFyrO0dZv1BIHTLhwZNTHbk V6L4CoKwwR8Y5+OiTMiZyqHMUWy7cm+xIALUjj1qzg4FOwsl8Eh5ErN8QHcKrkVzw2BE YpwQ== 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) From: Adhemerval Zanella 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 Content-Transfer-Encoding: 8bit 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 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 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; +} -- 2.34.1