https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108196

            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] <= input < cl_options[mn + 1].  */
  while (mx - mn > 1)
    {
      md = (mn + mx) / 2;
      opt_len = cl_options[md].opt_len;
      comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);

      if (comp < 0)
        mx = md;
      else
        mn = md;
    }

When md is the exact match, the search doesn't terminate and we may get the
wrong result.

Reply via email to