From 77d228468dc179bc75fbda017cce56a5e1bb0b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 13 Nov 2019 12:59:55 +0100 Subject: [PATCH] libxl: use GRegex in libxlGetAutoballoonConf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the use of regcomp with GRegex. Signed-off-by: Ján Tomko Reviewed-by: Peter Krempa --- src/libxl/libxl_conf.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 920f228d6a..be7d85b264 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -22,7 +22,6 @@ #include -#include #include #include #include @@ -1664,7 +1663,8 @@ static int libxlGetAutoballoonConf(libxlDriverConfigPtr cfg, virConfPtr conf) { - regex_t regex; + g_autoptr(GRegex) regex = NULL; + g_autoptr(GError) err = NULL; int res; res = virConfGetValueBool(conf, "autoballoon", &cfg->autoballoon); @@ -1673,21 +1673,15 @@ libxlGetAutoballoonConf(libxlDriverConfigPtr cfg, else if (res == 1) return 0; - if ((res = regcomp(®ex, - "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )", - REG_NOSUB | REG_EXTENDED)) != 0) { - char error[100]; - regerror(res, ®ex, error, sizeof(error)); + regex = g_regex_new("(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )", + 0, 0, &err); + if (!regex) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to compile regex %s"), - error); - + _("Failed to compile regex %s"), err->message); return -1; } - res = regexec(®ex, cfg->verInfo->commandline, 0, NULL, 0); - regfree(®ex); - cfg->autoballoon = res == REG_NOMATCH; + cfg->autoballoon = !g_regex_match(regex, cfg->verInfo->commandline, 0, NULL); return 0; } -- GitLab