diff mbox series

[19/21] Warn if user-supplied regexes fail to compile.

Message ID 20200423154441.170531-20-gprocida@google.com
State Superseded
Headers show
Series Simplify regex and suppression parsing. | expand

Commit Message

Giuliano Procida April 23, 2020, 3:44 p.m. UTC
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(+)
diff mbox series

Patch

diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h
index 2618e2d0..cae2dfb0 100644
--- a/src/abg-corpus-priv.h
+++ b/src/abg-corpus-priv.h
@@ -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_;
diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index 3db2b7b1..8632d028 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -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 =