[libvirt PATCH v2 08/10] tests: Prevent malloc with size 0

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

 



Found by clang-tidy's "clang-analyzer-optin.portability.UnixAPI" check.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 tests/commandhelper.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index bf6a5baa40..b3c65ab3cc 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -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;
 
-- 
2.26.2




[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]

  Powered by Linux