From b96e0dbba9c67444c77dd8cfdfc56a9ab70fbf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 13 Nov 2019 16:01:19 +0100 Subject: [PATCH] util: use GRegex in virStringMatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ján Tomko Reviewed-by: Peter Krempa --- src/util/virstring.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index 121a5c33b0..40c83841e9 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -19,7 +19,6 @@ #include #include -#include #include #include "c-ctype.h" @@ -1089,24 +1088,18 @@ bool virStringMatch(const char *str, const char *regexp) { - regex_t re; - int rv; + g_autoptr(GRegex) regex = NULL; + g_autoptr(GError) err = NULL; VIR_DEBUG("match '%s' for '%s'", str, regexp); - if ((rv = regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB)) != 0) { - char error[100]; - regerror(rv, &re, error, sizeof(error)); - VIR_WARN("error while compiling regular expression '%s': %s", - regexp, error); + regex = g_regex_new(regexp, 0, 0, &err); + if (!regex) { + VIR_WARN("Failed to compile regex %s", err->message); return false; } - rv = regexec(&re, str, 0, NULL, 0); - - regfree(&re); - - return rv == 0; + return g_regex_match(regex, str, 0, NULL); } /** -- GitLab