Re: [PATCH v2 2/3] Add test case for virHashEqual function

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

 



On 18.01.2012 17:20, Stefan Berger wrote:
> +
> +static int
> +testHashEqual(const void *data ATTRIBUTE_UNUSED)
> +{
> +    virHashTablePtr hash1, hash2;
> +    int ret = -1;
> +    char keya[] = "a";
> +    char keyb[] = "b";
> +    char keyc[] = "c";
> +    char value1[] = "1";
> +    char value2[] = "2";
> +    char value3[] = "3";
> +    char value4[] = "4";
> +
> +    if (!(hash1 = virHashCreate(0, NULL)) ||
> +        !(hash2 = virHashCreate(0, NULL)) ||

Actually, if the first virHashCreate() returns NULL, hash2 remains
uninitialized and we jump

> +        virHashAddEntry(hash1, keya, value1) < 0 ||
> +        virHashAddEntry(hash1, keyb, value2) < 0 ||
> +        virHashAddEntry(hash1, keyc, value3) < 0 ||
> +        virHashAddEntry(hash2, keya, value1) < 0 ||
> +        virHashAddEntry(hash2, keyb, value2) < 0) {
> +        if (virTestGetVerbose()) {
> +            testError("\nfailed to create hashes");
> +        }
> +        goto cleanup;
> +    }

over here and do free() on uninitialized pointer.
> +
> +cleanup:
> +    virHashFree(hash1);
> +    virHashFree(hash2);
> +    return ret;
> +}

Therefore I am pushing this under trivial and build-breaker rules (yeah,
one thing - and perhaps the only one - i like about 4.6 gcc is enhanced
static analysis as I spotted warning while compiling current HEAD):

Author: Michal Privoznik <mprivozn@xxxxxxxxxx>
Date:   Tue Jan 24 12:09:42 2012 +0100

    hashtest: Initialize variable in virHashEqual test

    One of latest patches (b7bcb22ce2) enhanced testing for virHashEqual.
    However, hash2 variable might be used uninitialized.

diff --git a/tests/hashtest.c b/tests/hashtest.c
index 6c45b01..441672c 100644
--- a/tests/hashtest.c
+++ b/tests/hashtest.c
@@ -583,7 +583,7 @@ testHashEqualCompValue(const void *value1, const
void *value2)
 static int
 testHashEqual(const void *data ATTRIBUTE_UNUSED)
 {
-    virHashTablePtr hash1, hash2;
+    virHashTablePtr hash1, hash2 = NULL;
     int ret = -1;
     char keya[] = "a";
     char keyb[] = "b";

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


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