[19/21] Warn if user-supplied regexes fail to compile.
Commit Message
There are not many calls to regex::compile in the code base. Two of
these pass internally-generated regexes and are followed by assertions
that the regexes compile.
The remaining cases deal with user-supplied regexes. If these fail to
compile they are currently silently ignored.
This patch makes sure failures now result in warning messages on
stderr, but otherwise does not change program behaviour.
* src/abg-corpus-priv.h
(corpus::exported_decls_builder::priv::compiled_regex_fns_suppress):
Emit a warning message if regex::compile fails.
(corpus::exported_decls_builder::priv::compiled_regex_fns_keep):
Ditto.
(corpus::exported_decls_builder::priv::compiled_regex_vars_suppress):
Ditto.
(corpus::exported_decls_builder::priv::compiled_regex_vars_keep):
Ditto.
* src/abg-suppression.cc (maybe_get_string_prop): Ditto.
(read_parameter_spec_from_string): Ditto.
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
src/abg-corpus-priv.h | 8 ++++++++
src/abg-suppression.cc | 4 ++++
2 files changed, 12 insertions(+)
@@ -126,6 +126,8 @@ public:
regex_t_sptr r = regex::compile(*i);
if (r)
compiled_fns_suppress_regexp_.push_back(r);
+ else
+ std::cerr << "warning: bad regex '" << *i << "'\n";
}
}
return compiled_fns_suppress_regexp_;
@@ -148,6 +150,8 @@ public:
regex_t_sptr r = regex::compile(*i);
if (r)
compiled_fns_keep_regexps_.push_back(r);
+ else
+ std::cerr << "warning: bad regex '" << *i << "'\n";
}
}
return compiled_fns_keep_regexps_;
@@ -170,6 +174,8 @@ public:
regex_t_sptr r = regex::compile(*i);
if (r)
compiled_vars_suppress_regexp_.push_back(r);
+ else
+ std::cerr << "warning: bad regex '" << *i << "'\n";
}
}
return compiled_vars_suppress_regexp_;
@@ -192,6 +198,8 @@ public:
regex_t_sptr r = regex::compile(*i);
if (r)
compiled_vars_keep_regexps_.push_back(r);
+ else
+ std::cerr << "warning: bad regex '" << *i << "'\n";
}
}
return compiled_vars_keep_regexps_;
@@ -1644,6 +1644,8 @@ maybe_get_regex_prop(const ini::config::section& section,
if (!maybe_get_string_prop(section, name, str))
return false;
regex = regex::compile(str);
+ if (!regex)
+ std::cerr << "warning: bad regex '" << str << "'\n";
return true;
}
@@ -3161,6 +3163,8 @@ read_parameter_spec_from_string(const string& str)
if (is_regex)
{
type_name_regex = regex::compile(type_name);
+ if (!type_name_regex)
+ std::cerr << "warning: bad regex '" << type_name << "'\n";
type_name.clear();
}
function_suppression::parameter_spec* p =