]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStrncpy: fix to successfully copy empty string
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Mon, 16 Sep 2019 13:55:36 +0000 (16:55 +0300)
committerNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Wed, 18 Sep 2019 06:25:17 +0000 (09:25 +0300)
After [1] we got failure on attempt to copy empty string.
Before the patch empty string was copied successfuly.
Restore the original behaviour.

[1] 7d70a63b util: Improve virStrncpy() implementation

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/util/virstring.c

index 2064944b0bb17dcaa426032430fb34e03a897e1d..a4cc7e9c0a553293319e7c52eb60823bfeb8f427 100644 (file)
@@ -786,7 +786,7 @@ virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
     if (n == -1)
         n = src_len;
 
-    if (n <= 0 || n > src_len || n > (destbytes - 1))
+    if (n > src_len || n > (destbytes - 1))
         return -1;
 
     memcpy(dest, src, n);