]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
fix compile_rx_or_error
authorTom Tromey <tromey@redhat.com>
Thu, 30 May 2013 17:39:34 +0000 (17:39 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 30 May 2013 17:39:34 +0000 (17:39 +0000)
compile_rx_or_error looks like a constructor, but it can return NULL.
This patch changes it to remove the NULL return, making it work
like any other cleanup constructor.

This is a stylistic patch but I think it is also better for code to
follow the normal conventions.

* probe.c (collect_probes): Check arguments for NULL before
calling compile_rx_or_error.
* utils.c (compile_rx_or_error): Require 'rx' to be non-NULL.
Remove NULL return.

gdb/ChangeLog
gdb/probe.c
gdb/utils.c

index 7adba7755aa529bace13d571fa61507501bc85d7..142efca820ec65dd56be838b997bb4bd7119673c 100644 (file)
@@ -1,3 +1,10 @@
+2013-05-30  Tom Tromey  <tromey@redhat.com>
+
+       * probe.c (collect_probes): Check arguments for NULL before
+       calling compile_rx_or_error.
+       * utils.c (compile_rx_or_error): Require 'rx' to be non-NULL.
+       Remove NULL return.
+
 2013-05-30  Tom Tromey  <tromey@redhat.com>
 
        * infrun.c (adjust_pc_after_break): Introduce an outer null
index 05bdd1baef72cdb6321346cf86fe77428984122b..3086f4df35df52adad86d967e5e30091c816a4e0 100644 (file)
@@ -245,9 +245,12 @@ collect_probes (char *objname, char *provider, char *probe_name,
   cleanup = make_cleanup (VEC_cleanup (probe_p), &result);
 
   cleanup_temps = make_cleanup (null_cleanup, NULL);
-  compile_rx_or_error (&prov_pat, provider, _("Invalid provider regexp"));
-  compile_rx_or_error (&probe_pat, probe_name, _("Invalid probe regexp"));
-  compile_rx_or_error (&obj_pat, objname, _("Invalid object file regexp"));
+  if (provider != NULL)
+    compile_rx_or_error (&prov_pat, provider, _("Invalid provider regexp"));
+  if (probe_name != NULL)
+    compile_rx_or_error (&probe_pat, probe_name, _("Invalid probe regexp"));
+  if (objname != NULL)
+    compile_rx_or_error (&obj_pat, objname, _("Invalid object file regexp"));
 
   ALL_OBJFILES (objfile)
     {
index c25dadfe286b686d3f40509518d4a9b130e9d095..18ee9bbf98b4a88308394424cf3dbe94c01531c6 100644 (file)
@@ -1127,16 +1127,15 @@ get_regcomp_error (int code, regex_t *rx)
 }
 
 /* Compile a regexp and throw an exception on error.  This returns a
-   cleanup to free the resulting pattern on success.  If RX is NULL,
-   this does nothing and returns NULL.  */
+   cleanup to free the resulting pattern on success.  RX must not be
+   NULL.  */
 
 struct cleanup *
 compile_rx_or_error (regex_t *pattern, const char *rx, const char *message)
 {
   int code;
 
-  if (!rx)
-    return NULL;
+  gdb_assert (rx != NULL);
 
   code = regcomp (pattern, rx, REG_NOSUB);
   if (code != 0)