From 04dfa682c9ea913696838351464441c47a78314b Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Fri, 3 May 2024 09:19:21 +0200 Subject: [PATCH] Fix use of invalid flag with regexec() --- src/configfile.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index 22cf225..9572852 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -417,6 +417,7 @@ static char *match_and_replace(const char *str, const char *pattern, char *devic char *string = malloc(strlen(device) + PATH_MAX); if (string == NULL) { + tio_debug_printf("Failure allocating string memory\n"); return NULL; } strcpy(string, device); @@ -434,11 +435,12 @@ static char *match_and_replace(const char *str, const char *pattern, char *devic if (regcomp(®ex, pattern, REG_EXTENDED) != 0) { // Failure to compile regular expression - return NULL; + tio_error_print("Failure compiling regular expression '%s'\n", pattern); + exit(EXIT_FAILURE); } regmatch_t matches[regex.re_nsub + 1]; - int status = regexec(®ex, str, regex.re_nsub + 1, matches, REG_EXTENDED); + int status = regexec(®ex, str, regex.re_nsub + 1, matches, 0); if (status == 0) { tio_debug_printf("Full match: "); @@ -469,13 +471,14 @@ static char *match_and_replace(const char *str, const char *pattern, char *devic } else if (status == REG_NOMATCH) { + tio_debug_printf("No regex match\n"); goto error; } else { char error_message[100]; regerror(status, ®ex, error_message, sizeof(error_message)); - tio_error_print("Regex match failed: %s", error_message); + tio_debug_printf("Regex match failed: %s", error_message); goto error; }