[llvm-bugs] [Bug 30515] New: out of range iterator usage in getLongestCommonPrefixLen (r280895)
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Sep 25 01:15:11 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=30515
Bug ID: 30515
Summary: out of range iterator usage in
getLongestCommonPrefixLen (r280895)
Product: new-bugs
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: yaron.keren at gmail.com
CC: llvm-bugs at lists.llvm.org, vsk at apple.com
Classification: Unclassified
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:
http://en.cppreference.com/w/cpp/algorithm/mismatch
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160925/41f9cef6/attachment-0001.html>
More information about the llvm-bugs
mailing list