test: fix coverity 1475940: negative return
authorPauli <ppzgs1@gmail.com>
Sun, 4 Apr 2021 08:00:26 +0000 (18:00 +1000)
committerPauli <pauli@openssl.org>
Wed, 7 Apr 2021 13:30:42 +0000 (23:30 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14769)

test/dhtest.c

index 294c9e3f567a07edbf0ad95c1bfc3956676aee67..189b5ae13ffe74d4a85ea0722933b12926b1cf14 100644 (file)
@@ -249,9 +249,9 @@ static int dh_computekey_range_test(void)
         || !TEST_true(DH_set0_pqg(dh, p, q, g)))
         goto err;
     p = q = g = NULL;
-    sz = DH_size(dh);
 
-    if (!TEST_ptr(buf = OPENSSL_malloc(sz))
+    if (!TEST_int_gt(sz = DH_size(dh), 0)
+        || !TEST_ptr(buf = OPENSSL_malloc(sz))
         || !TEST_ptr(pub = BN_new())
         || !TEST_ptr(priv = BN_new()))
         goto err;