From 0b0ddb1e5fe5a96f0addfb04dba0568b143c1e5f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 2 Jan 2017 20:25:24 +0100 Subject: [PATCH] tweaks: rename a variable, chuck an assert, and frob a comment --- src/search.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/search.c b/src/search.c index 37dc0e2f..c2d0f30f 100644 --- a/src/search.c +++ b/src/search.c @@ -39,22 +39,19 @@ static bool history_changed = FALSE; static bool regexp_compiled = FALSE; /* Have we compiled any regular expressions? */ -/* Compile the regular expression regexp to see if it's valid. Return - * TRUE if it is, or FALSE otherwise. */ +/* Compile the given regular expression and store it in search_regexp. + * Return TRUE if the expression is valid, and FALSE otherwise. */ bool regexp_init(const char *regexp) { - int rc; - - assert(!regexp_compiled); - - rc = regcomp(&search_regexp, fixbounds(regexp), + int value = regcomp(&search_regexp, fixbounds(regexp), NANO_REG_EXTENDED | (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE)); - if (rc != 0) { - size_t len = regerror(rc, &search_regexp, NULL, 0); + /* If regex compilation failed, show the error message. */ + if (value != 0) { + size_t len = regerror(value, &search_regexp, NULL, 0); char *str = charalloc(len); - regerror(rc, &search_regexp, str, len); + regerror(value, &search_regexp, str, len); statusline(ALERT, _("Bad regex \"%s\": %s"), regexp, str); free(str);