<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - out of range iterator usage in getLongestCommonPrefixLen (r280895)"
   href="https://llvm.org/bugs/show_bug.cgi?id=30515">30515</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>out of range iterator usage in getLongestCommonPrefixLen (r280895)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yaron.keren@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, vsk@apple.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>getLongestCommonPrefixLen calls the three-argument version of std::mismatch:

        std::mismatch(Strings[0].begin(), Strings[0].end(), Strings[I].begin())

with this call, Strings[I].end() is *assumed* to be Strings[I].begin() +
Strings[0].end() - Strings[0].begin(), see:

<a href="http://en.cppreference.com/w/cpp/algorithm/mismatch">http://en.cppreference.com/w/cpp/algorithm/mismatch</a>
 If last2 is not provided (overloads (1-4)), it denotes first2 + (last1 -
first1).

in case String[I] is a prefix of Strings[0], std::mismatch will continue
increasing its iterator outside String[I]. This is caught by Visual C++ runtime
lib in debug mode, "string iterator + offset out of range". the code probably
works since the strings are null-terminated but at least VC thinks it is wrong.

the four-argument std::mismatch could solve this but sadly is C++ 17.
maybe it's best just to hardcode the while loop.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>