- bool ret;
-
- if (!matches || regcomp(&r, regex, REG_EXTENDED) != 0)
- return false;
-
- if (regexec(&r, string, nmatch, matches, 0) == 0) {
- unsigned int i;
- va_list ap;
-
- ret = true;
- va_start(ap, regex);
- for (i = 1; i < nmatch; i++) {
- char **arg;
- arg = va_arg(ap, char **);
- if (arg) {
- /* eg. ([a-z])? can give "no match". */
- if (matches[i].rm_so == -1)
- *arg = NULL;
- else {
- *arg = tal_strndup(ctx,
- string + matches[i].rm_so,
- matches[i].rm_eo
- - matches[i].rm_so);
- if (!*arg) {
- ret = false;
- break;
- }
+ bool ret = false;
+ unsigned int i;
+ va_list ap;
+
+ if (unlikely(!regex) && is_taken(regex))
+ goto fail_no_re;
+
+ if (regcomp(&r, regex, REG_EXTENDED) != 0)
+ goto fail_no_re;
+
+ if (unlikely(!string) && is_taken(string))
+ goto fail;
+
+ if (regexec(&r, string, nmatch, matches, 0) != 0)
+ goto fail;
+
+ ret = true;
+ va_start(ap, regex);
+ for (i = 1; i < nmatch; i++) {
+ char **arg = va_arg(ap, char **);
+ if (arg) {
+ /* eg. ([a-z])? can give "no match". */
+ if (matches[i].rm_so == -1)
+ *arg = NULL;
+ else {
+ *arg = tal_strndup(ctx,
+ string + matches[i].rm_so,
+ matches[i].rm_eo
+ - matches[i].rm_so);
+ /* FIXME: If we fail, we set some and leak! */
+ if (!*arg) {
+ ret = false;
+ break;