]> xenbits.xensource.com Git - libvirt.git/commitdiff
openvz: Use virStringSplitCount instead of strtok_r
authorJohn Ferlan <jferlan@redhat.com>
Fri, 19 Feb 2016 18:35:24 +0000 (13:35 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 25 Feb 2016 16:52:45 +0000 (11:52 -0500)
When parsing the barrier:limit values, use virStringSplitCount in order
to split the pair and make the approriate checks to get the data.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/openvz/openvz_conf.c

index e32dd6f3af2088fcd7d401fce05661ca889bc708..4103d6998d0de61bd91d3ae5336872ee416de550 100644 (file)
@@ -133,35 +133,25 @@ openvzParseBarrierLimit(const char* value,
                         unsigned long long *barrier,
                         unsigned long long *limit)
 {
-    char *token;
-    char *saveptr = NULL;
-    char *str;
+    char **tmp = NULL;
+    size_t ntmp = 0;
     int ret = -1;
 
-    if (VIR_STRDUP(str, value) < 0)
+    if (!(tmp = virStringSplitCount(value, ":", 0, &ntmp)))
         goto error;
 
-    token = strtok_r(str, ":", &saveptr);
-    if (token == NULL) {
+    if (ntmp != 2)
         goto error;
-    } else {
-        if (barrier != NULL) {
-            if (virStrToLong_ull(token, NULL, 10, barrier))
-                goto error;
-        }
-    }
-    token = strtok_r(NULL, ":", &saveptr);
-    if (token == NULL) {
+
+    if (barrier && virStrToLong_ull(tmp[0], NULL, 10, barrier) < 0)
         goto error;
-    } else {
-        if (limit != NULL) {
-            if (virStrToLong_ull(token, NULL, 10, limit))
-                goto error;
-        }
-    }
+
+    if (limit && virStrToLong_ull(tmp[1], NULL, 10, limit) < 0)
+        goto error;
+
     ret = 0;
  error:
-    VIR_FREE(str);
+    virStringFreeListCount(tmp, ntmp);
     return ret;
 }