Regex::match stack-use-after-scope
Regex::match
takes a const Glib::ustring&
argument and then passes c_str()
to g_regex_match
. This is a problem because:
string
is not copied and is used inGMatchInfo
internally. If you use anyGMatchInfo
method (exceptg_match_info_free()
) after freeing or modifyingstring
then the behaviour is undefined.
This code produces stack-use-after-scope
:
auto regex = Glib::Regex::create("(\\w+)");
Glib::MatchInfo matchInfo;
regex->match("this is not a Glib::ustring const reference", matchInfo);
while (matchInfo.matches()) {
std::cout << matchInfo.fetch(1) << std::endl;
matchInfo.next();
}
Using Glib::UStringView
with Regex::match
will fix this.
/cc @kjellahl
Edited by Thomas Holder