Skip to content
Snippets Groups Projects
Commit 0359bfbc authored by Nikita Nemkin's avatar Nikita Nemkin Committed by Brad King
Browse files

RegularExpression: Fix match start/end values of unmatched groups

CMake assumes that Match::start(n) and end(n) return npos
for unmatched groups. Make it so and prevent undefined behavior
(pointer overflow).

Issue: cmake/cmake#16899
parent 98452164
No related branches found
No related tags found
1 merge request!317RegularExpression: Add an optional offset parameter to find()
......@@ -121,6 +121,9 @@ inline std::string::size_type RegularExpressionMatch::end() const
*/
inline std::string::size_type RegularExpressionMatch::start(int n) const
{
if (!this->startp[n]) {
return std::string::npos;
}
return static_cast<std::string::size_type>(this->startp[n] -
this->searchstring);
}
......@@ -131,6 +134,9 @@ inline std::string::size_type RegularExpressionMatch::start(int n) const
*/
inline std::string::size_type RegularExpressionMatch::end(int n) const
{
if (!this->endp[n]) {
return std::string::npos;
}
return static_cast<std::string::size_type>(this->endp[n] -
this->searchstring);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment