提交 c4ac8e41 编写于 作者: J Ján Tomko

libxl: use GRegex in xenParseSxprVifRate

Use GRegex from GLib instead of regcomp.
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NPeter Krempa <pkrempa@redhat.com>
上级 5c98d442
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#include <config.h> #include <config.h>
#include <regex.h>
#include "internal.h" #include "internal.h"
#include "virerror.h" #include "virerror.h"
#include "virconf.h" #include "virconf.h"
...@@ -1063,10 +1061,10 @@ static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$"; ...@@ -1063,10 +1061,10 @@ static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$";
static int static int
xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec) xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec)
{ {
g_autoptr(GRegex) regex = NULL;
g_autoptr(GError) err = NULL;
g_autofree char *trate = NULL; g_autofree char *trate = NULL;
char *p; char *p;
regex_t rec;
int err;
char *suffix; char *suffix;
unsigned long long tmp; unsigned long long tmp;
int ret = -1; int ret = -1;
...@@ -1077,17 +1075,14 @@ xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec) ...@@ -1077,17 +1075,14 @@ xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec)
if (p != NULL) if (p != NULL)
*p = 0; *p = 0;
err = regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED|REG_NOSUB); regex = g_regex_new(vif_bytes_per_sec_re, 0, 0, &err);
if (err != 0) { if (!regex) {
char error[100];
regerror(err, &rec, error, sizeof(error));
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to compile regular expression '%s': %s"), _("Failed to compile regex %s"), err->message);
vif_bytes_per_sec_re, error); return -1;
goto cleanup;
} }
if (regexec(&rec, trate, 0, NULL, 0)) { if (!g_regex_match(regex, trate, 0, NULL)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid rate '%s' specified"), rate); _("Invalid rate '%s' specified"), rate);
goto cleanup; goto cleanup;
...@@ -1111,7 +1106,6 @@ xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec) ...@@ -1111,7 +1106,6 @@ xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec)
ret = 0; ret = 0;
cleanup: cleanup:
regfree(&rec);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册