This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 39/40] fix compile_rx_or_error
- From: Tom Tromey <tromey at redhat dot com>
- To: Yao Qi <yao at codesourcery dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Thu, 30 May 2013 11:39:20 -0600
- Subject: Re: [PATCH 39/40] fix compile_rx_or_error
- References: <cover dot 1368124285 dot git dot tromey at redhat dot com> <b742ab349892cce15df6d761190d17eb27a23976 dot 1368124285 dot git dot tromey at redhat dot com> <519055B5 dot 10803 at codesourcery dot com> <87y5bjc4dq dot fsf at fleche dot redhat dot com>
Yao> Do we need an assert on RX here?
Tom> It can't hurt, but I think the subsequent regcomp will just crash.
Tom> I will add one.
For the record, here is what I am checking in.
Tom
* 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.
diff --git a/gdb/probe.c b/gdb/probe.c
index 05bdd1b..3086f4d 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -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)
{
diff --git a/gdb/utils.c b/gdb/utils.c
index c25dadf..18ee9bb 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -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)