From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id BDE501F8C4 for ; Sat, 6 Feb 2021 01:26:39 +0000 (UTC) Received: from localhost ([::1]:37996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8CMw-0004FN-EN for normalperson@yhbt.net; Fri, 05 Feb 2021 20:26:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8CMe-0004Ew-Bg for bug-gnulib@gnu.org; Fri, 05 Feb 2021 20:26:20 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8CMa-0001Q2-8M for bug-gnulib@gnu.org; Fri, 05 Feb 2021 20:26:19 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 48EC316012C for ; Fri, 5 Feb 2021 17:26:14 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 2MN4C1qZfPZc; Fri, 5 Feb 2021 17:26:13 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7BE1616013E; Fri, 5 Feb 2021 17:26:13 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cDtlNlDCUP17; Fri, 5 Feb 2021 17:26:13 -0800 (PST) Received: from day.example.com (cpe-23-243-218-95.socal.res.rr.com [23.243.218.95]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5222816012C; Fri, 5 Feb 2021 17:26:13 -0800 (PST) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH 03/10] regex: minor refactoring Date: Fri, 5 Feb 2021 17:25:55 -0800 Message-Id: <20210206012602.2257711-3-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210206012602.2257711-1-eggert@cs.ucla.edu> References: <20210206012602.2257711-1-eggert@cs.ucla.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * lib/regexec.c (proceed_next_node): Use more-local decls. --- ChangeLog | 3 +++ lib/regexec.c | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fcd5819f..fdc107673 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-02-05 Paul Eggert =20 + regex: minor refactoring + * lib/regexec.c (proceed_next_node): Use more-local decls. + regex: avoid undefined behavior * lib/regexec.c (pop_fail_stack): If the stack is empty, return -1 instead of indulging in undefined behavior. This simplifies diff --git a/lib/regexec.c b/lib/regexec.c index f982e3aba..fdd2e373e 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -1215,19 +1215,17 @@ proceed_next_node (const re_match_context_t *mctx= , Idx nregs, regmatch_t *regs, struct re_fail_stack_t *fs) { const re_dfa_t *const dfa =3D mctx->dfa; - Idx i; - bool ok; if (IS_EPSILON_NODE (dfa->nodes[node].type)) { re_node_set *cur_nodes =3D &mctx->state_log[*pidx]->nodes; re_node_set *edests =3D &dfa->edests[node]; - Idx dest_node; - ok =3D re_node_set_insert (eps_via_nodes, node); + bool ok =3D re_node_set_insert (eps_via_nodes, node); if (__glibc_unlikely (! ok)) return -2; - /* Pick up a valid destination, or return -1 if none - is found. */ - for (dest_node =3D -1, i =3D 0; i < edests->nelem; ++i) + + /* Pick a valid destination, or return -1 if none is found. */ + Idx dest_node =3D -1; + for (Idx i =3D 0; i < edests->nelem; i++) { Idx candidate =3D edests->elems[i]; if (!re_node_set_contains (cur_nodes, candidate)) @@ -1289,7 +1287,7 @@ proceed_next_node (const re_match_context_t *mctx, = Idx nregs, regmatch_t *regs, if (naccepted =3D=3D 0) { Idx dest_node; - ok =3D re_node_set_insert (eps_via_nodes, node); + bool ok =3D re_node_set_insert (eps_via_nodes, node); if (__glibc_unlikely (! ok)) return -2; dest_node =3D dfa->edests[node].elems[0]; --=20 2.27.0