[llvm] [FIX] Fix undefined-behaviour in regex engine. (PR #73071)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 00:56:37 PST 2023
================
@@ -82,8 +82,8 @@ unsigned Regex::getNumMatches() const {
bool Regex::match(StringRef String, SmallVectorImpl<StringRef> *Matches,
std::string *Error) const {
- // Exit without match if string is empty
- if (String.empty())
+ // No match for null string data
+ if (String.data() == nullptr)
----------------
nikic wrote:
Ah sorry, it looks like I was looking at the diff from only the last commit and thought the empty() check is pre-existing and you're changing it to check nullptr instead.
I believe what you want to do is below where String.data() is used, if it it nullptr pass "" instead. That should handle cases where the regex matches an empty string without passing nullptr into the implementation.
https://github.com/llvm/llvm-project/pull/73071
More information about the llvm-commits
mailing list