[PATCH 2/2] Adapt to new VIR_STRNDUP behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



With previous patch, we accept negative value as length of string to
duplicate. So there is no need to pass strlen(src) in case we want to do
duplicate the whole string.
---
 src/conf/domain_conf.c  |  6 ++----
 src/qemu/qemu_command.c | 14 ++++++--------
 src/util/virsexpr.c     |  2 +-
 src/xenxs/xen_sxpr.c    |  4 ++--
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ad5550c..a9656af 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17370,8 +17370,7 @@ virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
         return 0;
     }
 
-    if (VIR_STRNDUP(listenInfo->address, address,
-                    len == -1 ? strlen(address) : len) < 0)
+    if (VIR_STRNDUP(listenInfo->address, address, len) < 0)
         return -1;
     return 0;
 }
@@ -17409,8 +17408,7 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def,
         return 0;
     }
 
-    if (VIR_STRNDUP(listenInfo->network, network,
-                    len == -1 ? strlen(network) : len) < 0)
+    if (VIR_STRNDUP(listenInfo->network, network, len) < 0)
         return -1;
     return 0;
 }
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 434f5a7..0373626 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8674,7 +8674,7 @@ static int qemuStringToArgvEnv(const char *args,
         if (!next)
             next = strchr(curr, '\n');
 
-        if (VIR_STRNDUP(arg, curr, next ? next - curr : strlen(curr)) < 0)
+        if (VIR_STRNDUP(arg, curr, next ? next - curr : -1) < 0)
             goto error;
 
         if (next && (*next == '\'' || *next == '"'))
@@ -9566,16 +9566,14 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
         if (VIR_STRNDUP(source->data.tcp.host, val, svc - val) < 0)
             goto error;
         svc++;
-        if (VIR_STRNDUP(source->data.tcp.service, svc,
-                        opt ? opt - svc : strlen(svc)) < 0)
+        if (VIR_STRNDUP(source->data.tcp.service, svc, opt ? opt - svc : -1) < 0)
             goto error;
     } else if (STRPREFIX(val, "unix:")) {
         const char *opt;
         val += strlen("unix:");
         opt = strchr(val, ',');
         source->type = VIR_DOMAIN_CHR_TYPE_UNIX;
-        if (VIR_STRNDUP(source->data.nix.path, val,
-                        opt ? opt - val : strlen(val)) < 0)
+        if (VIR_STRNDUP(source->data.nix.path, val, opt ? opt - val : -1) < 0)
             goto error;
 
     } else if (STRPREFIX(val, "/dev")) {
@@ -9634,7 +9632,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             next++;
 
         if (p == val) {
-            if (VIR_STRNDUP(model, p, next ? next - p - 1 : strlen(p)) < 0)
+            if (VIR_STRNDUP(model, p, next ? next - p - 1 : -1) < 0)
                 goto error;
 
             if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) {
@@ -9658,7 +9656,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             if (*p == '\0' || *p == ',')
                 goto syntax;
 
-            if (VIR_STRNDUP(feature, p, next ? next - p - 1 : strlen(p)) < 0)
+            if (VIR_STRNDUP(feature, p, next ? next - p - 1 : -1) < 0)
                 goto error;
 
             if (STREQ(feature, "kvmclock")) {
@@ -9717,7 +9715,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             if (*p == '\0' || *p == ',')
                 goto syntax;
 
-            if (VIR_STRNDUP(feature, p, next ? next - p - 1 : strlen(p)) < 0)
+            if (VIR_STRNDUP(feature, p, next ? next - p - 1 : -1) < 0)
                 goto error;
 
             dom->features |= (1 << VIR_DOMAIN_FEATURE_HYPERV);
diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c
index c75dfd9..7db215a 100644
--- a/src/util/virsexpr.c
+++ b/src/util/virsexpr.c
@@ -120,7 +120,7 @@ sexpr_string(const char *str, ssize_t len)
         return ret;
     ret->kind = SEXPR_VALUE;
 
-    if (VIR_STRNDUP(ret->u.value, str, len > 0 ? len : strlen(str)) < 0)
+    if (VIR_STRNDUP(ret->u.value, str, len) < 0)
         VIR_FREE(ret);
 
     return ret;
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index c17aa5d..394b814 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -242,7 +242,7 @@ xenParseSxprChar(const char *value,
         offset2 = strchr(offset, ',');
         offset++;
         if (VIR_STRNDUP(def->source.data.tcp.service, offset,
-                        offset2 ? offset2 - offset : strlen(offset)) < 0)
+                        offset2 ? offset2 - offset : -1) < 0)
             goto error;
 
         if (offset2 && strstr(offset2, ",server"))
@@ -296,7 +296,7 @@ xenParseSxprChar(const char *value,
     {
         const char *offset = strchr(value, ',');
         if (VIR_STRNDUP(def->source.data.nix.path, value,
-                        offset ? offset - value : strlen(value)) < 0)
+                        offset ? offset - value : -1) < 0)
             goto error;
 
         if (offset != NULL &&
-- 
1.8.2.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]