From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7A56E3858D1E; Wed, 21 Dec 2022 20:10:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A56E3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671653422; bh=Oazn2xuWhZaA2lihUth0jbBXZgkYAMKZUD5WZW+l7L4=; h=From:To:Subject:Date:From; b=PO/Mm5+syM7nhpukVYbrLmvq3qD3Wth38WIDZc7YQ6CNx1tXl2yeSvj1i8qVF1C5U P5ajvow844LDmDaJD1Mbm5+FaduMhelLL2IK3Z+5U2qXeELZU4N8oDCVMTl4wYzu77 G0FG474vBejUo/XQ5clapLK0G9y7X9hF+HnhB7dY= From: "hjl.tools at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug driver/108196] New: Incorrect binary search in find_opt Date: Wed, 21 Dec 2022 20:10:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: driver X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hjl.tools at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108196 Bug ID: 108196 Summary: Incorrect binary search in find_opt Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com Target Milestone: --- opts-common.cc has /* Find mn such this lexicographical inequality holds: cl_options[mn] <=3D input < cl_options[mn + 1]. */ while (mx - mn > 1) { md =3D (mn + mx) / 2; opt_len =3D cl_options[md].opt_len; comp =3D strncmp (input, cl_options[md].opt_text + 1, opt_len); if (comp < 0) mx =3D md; else mn =3D md; } When md is the exact match, the search doesn't terminate and we may get the wrong result.=