From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 840D73858D37; Mon, 4 Apr 2022 18:50:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 840D73858D37 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Remove null sentinel from 'attributes' X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 81eaa5061095f972d48e8160a4f677bd3e6ace51 X-Git-Newrev: c3f2a3738a3603f51e3621504d8207767526add9 Message-Id: <20220404185020.840D73858D37@sourceware.org> Date: Mon, 4 Apr 2022 18:50:20 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2022 18:50:20 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc3f2a3738a36= 03f51e3621504d8207767526add9 commit c3f2a3738a3603f51e3621504d8207767526add9 Author: Tom Tromey Date: Tue Feb 22 11:05:41 2022 -0700 Remove null sentinel from 'attributes' =20 In a subsequent patch, it's handy if the 'attributes' array in ada-lex.l does not have a NULL sentinel at the end. In C++, this is easy to avoid. Diff: --- gdb/ada-lex.l | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index 27470a75653..a0c9816e568 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -655,7 +655,6 @@ attributes[] =3D { { "size", TICK_SIZE }, { "tag", TICK_TAG }, { "val", TICK_VAL }, - { NULL, -1 } }; =20 /* Return the syntactic code corresponding to the attribute name or @@ -664,24 +663,23 @@ attributes[] =3D { static int processAttribute (const char *str) { - int i, k; + for (const auto &item : attributes) + if (strcasecmp (str, item.name) =3D=3D 0) + return item.code; =20 - for (i =3D 0; attributes[i].code !=3D -1; i +=3D 1) - if (strcasecmp (str, attributes[i].name) =3D=3D 0) - return attributes[i].code; - - for (i =3D 0, k =3D -1; attributes[i].code !=3D -1; i +=3D 1) - if (subseqMatch (str, attributes[i].name)) + gdb::optional found; + for (const auto &item : attributes) + if (subseqMatch (str, item.name)) { - if (k =3D=3D -1) - k =3D i; + if (!found.has_value ()) + found =3D item.code; else error (_("ambiguous attribute name: `%s'"), str); } - if (k =3D=3D -1) + if (!found.has_value ()) error (_("unrecognized attribute: `%s'"), str); =20 - return attributes[k].code; + return *found; } =20 /* Back up lexptr by yyleng and then to the rightmost occurrence of