]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Verify two bytes at once when testing chunk_clear()
authorTobias Brunner <tobias@strongswan.org>
Wed, 2 Apr 2014 09:50:11 +0000 (11:50 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 2 Apr 2014 09:50:11 +0000 (11:50 +0200)
This reduces the chances of arbitrary test failures if the memory area
already got overwritten.

src/libstrongswan/tests/suites/test_chunk.c

index e373fbdb623e5e841c00775f773d2fde8e2d22f2..34ace28944871341f5b76a6a7ddfec6b5b28082b 100644 (file)
@@ -117,10 +117,13 @@ START_TEST(test_chunk_clear)
        }
        chunk_clear(&chunk);
        /* check memory area of freed chunk. We can't use ck_assert() for this
-        * test directly, as it might allocate data at the freed area. */
-       for (i = 0; i < 64; i++)
+        * test directly, as it might allocate data at the freed area.  comparing
+        * two bytes at once reduces the chances of conflicts if memory got
+        * overwritten already */
+       for (i = 0; i < 64; i += 2)
        {
-               if (ptr[i] != 0 && ptr[i] == i)
+               if (ptr[i] != 0 && ptr[i] == i &&
+                       ptr[i+1] != 0 && ptr[i+1] == i+1)
                {
                        cleared = FALSE;
                        break;