From: Tim Wiederhake Date: Mon, 1 Feb 2021 12:42:05 +0000 (+0100) Subject: tests: Prevent malloc with size 0 X-Git-Tag: v7.1.0-rc1~335 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b62e51e5405becf679e05153666088e5d7b5bb91;p=thirdparty%2Flibvirt.git tests: Prevent malloc with size 0 Found by clang-tidy's "clang-analyzer-optin.portability.UnixAPI" check. Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- 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;