From patchwork Wed Jan 6 18:17:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41654 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 A9365384A023; Wed, 6 Jan 2021 18:17:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9365384A023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609957038; bh=GU1hEC5klfjsdexKzmGn5GlVxjBJq1i1Lx/CdWKSiyA=; 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=HFZ31EeUXX3PjZtpxiMz5RY05hLOKGuxsj7cywG8az4OyMKD+4aawSwHdklqhs40W f1CrocvS9d/PQGaozHekiRf4LzDXdYKAfvma0GvbrjuA3umsPlLhpHwpGno4dU2bxk dKFvnC+jN9ScamPQdi95dseLtvkcKBznAXstvW3E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by sourceware.org (Postfix) with ESMTPS id D8FAF384A87C for ; Wed, 6 Jan 2021 18:17:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D8FAF384A87C Received: by mail-qv1-xf30.google.com with SMTP id l14so1644903qvh.2 for ; Wed, 06 Jan 2021 10:17:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GU1hEC5klfjsdexKzmGn5GlVxjBJq1i1Lx/CdWKSiyA=; b=gOLn0jzwRf+PBTgTXsgwPyF6aKTJqzFBXae8zLf6EHXkzjv0VTecVw+FTTeAo39Odb SXSpCfO2HLCrDIZzs6M+PSa4cWigpkGkHaORt9UNaRsqNNcrAazY4PKJgLair2KiH5Yh nMAQCJa6BtWqfQem2onMlNQga0/k4Ey3Ys02jBR/wmV2NSlTkAIyt+DPSvP+MD0r8PoC FdNfQkatrnPvM3sWB+KyIBXGhtiIvMjn6G9pEvt3xt6x0mJMBFRCu/KzqtJaCCveeMuD ByT7EM8PeZ9ciptda1SdHpR0pn3STk/iqSh1oZykxKD4/78dr3MTCSHK1liD1TrqJvDw 5B6A== X-Gm-Message-State: AOAM530mrQWryLK8wQzYHaesZOsxeKuMWbLduwarTWERxI1dgGt8zRhL PiRpaOAqH41e6gB/mkO9x/xcFFfcPbU5+A== X-Google-Smtp-Source: ABdhPJymbki5FpmVyQs34JHcVG3uqJmHAFRlQM/aTcEaSaOvMHwfieYFFvkbIyWaV4M0XVUCxY049A== X-Received: by 2002:a0c:a994:: with SMTP id a20mr5077756qvb.30.1609957034769; Wed, 06 Jan 2021 10:17:14 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id a194sm1762745qkc.70.2021.01.06.10.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 10:17:14 -0800 (PST) To: libc-alpha@sourceware.org, Paul Eggert , bug-gnulib@gnu.org Subject: [PATCH 2/3] posix: Remove alloca usage on regex build_trtable Date: Wed, 6 Jan 2021 15:17:06 -0300 Message-Id: <20210106181707.1738066-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210106181707.1738066-1-adhemerval.zanella@linaro.org> References: <20210106181707.1738066-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@sourceware.org Sender: "Libc-alpha" __libc_use_alloca/alloca is replaced with malloc regardless. Checked on x86_64-linux-gnu. --- posix/regexec.c | 50 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/posix/regexec.c b/posix/regexec.c index 5e22f90842..a8e9a9cd01 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -3259,8 +3259,6 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) int ch; bool need_word_trtable = false; bitset_word_t elem, mask; - bool dests_node_malloced = false; - bool dest_states_malloced = false; Idx ndests; /* Number of the destination states from 'state'. */ re_dfastate_t **trtable; re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; @@ -3278,15 +3276,9 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) from 'state'. 'dests_node[i]' represents the nodes which i-th destination state contains, and 'dests_ch[i]' represents the characters which i-th destination state accepts. */ - if (__libc_use_alloca (sizeof (struct dests_alloc))) - dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); - else - { - dests_alloc = re_malloc (struct dests_alloc, 1); - if (__glibc_unlikely (dests_alloc == NULL)) - return false; - dests_node_malloced = true; - } + dests_alloc = re_malloc (struct dests_alloc, 1); + if (__glibc_unlikely (dests_alloc == NULL)) + return false; dests_node = dests_alloc->dests_node; dests_ch = dests_alloc->dests_ch; @@ -3298,8 +3290,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); if (__glibc_unlikely (ndests <= 0)) { - if (dests_node_malloced) - re_free (dests_alloc); + re_free (dests_alloc); /* Return false in case of an error, true otherwise. */ if (ndests == 0) { @@ -3323,26 +3314,17 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) if (__glibc_unlikely (ndests_max < ndests)) goto out_free; - if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX - + ndests * 3 * sizeof (re_dfastate_t *))) - dest_states = (re_dfastate_t **) - alloca (ndests * 3 * sizeof (re_dfastate_t *)); - else + dest_states = + re_malloc (re_dfastate_t *, ndests * 3 * sizeof (re_dfastate_t *)); + if (__glibc_unlikely (dest_states == NULL)) { - dest_states = re_malloc (re_dfastate_t *, ndests * 3); - if (__glibc_unlikely (dest_states == NULL)) - { out_free: - if (dest_states_malloced) - re_free (dest_states); - re_node_set_free (&follows); - for (i = 0; i < ndests; ++i) - re_node_set_free (dests_node + i); - if (dests_node_malloced) - re_free (dests_alloc); - return false; - } - dest_states_malloced = true; + re_free (dest_states); + re_node_set_free (&follows); + for (i = 0; i < ndests; ++i) + re_node_set_free (dests_node + i); + re_free (dests_alloc); + return false; } dest_states_word = dest_states + ndests; dest_states_nl = dest_states_word + ndests; @@ -3470,15 +3452,13 @@ out_free: } } - if (dest_states_malloced) - re_free (dest_states); + re_free (dest_states); re_node_set_free (&follows); for (i = 0; i < ndests; ++i) re_node_set_free (dests_node + i); - if (dests_node_malloced) - re_free (dests_alloc); + re_free (dests_alloc); return true; }