]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: Prevent malloc with size 0
authorTim Wiederhake <twiederh@redhat.com>
Mon, 1 Feb 2021 12:42:05 +0000 (13:42 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Feb 2021 14:00:55 +0000 (15:00 +0100)
Found by clang-tidy's "clang-analyzer-optin.portability.UnixAPI" check.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tests/commandhelper.c

index bf6a5baa4093b0c88e4db34953b6a8bc7be203b0..b3c65ab3cc2ed8b36bde15d565de40cf42a07cec 100644 (file)
@@ -156,6 +156,9 @@ static int printEnvironment(FILE *log)
     for (length = 0; environ[length]; length++) {
     }
 
+    if (length == 0)
+        return 0;
+
     if (!(newenv = malloc(sizeof(*newenv) * length)))
         return -1;