unit-tests: don't use ck_assert() to test a cleared chunk, as it allocates data
authorMartin Willi <martin@revosec.ch>
Tue, 11 Jun 2013 16:29:49 +0000 (18:29 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 21 Jun 2013 08:53:22 +0000 (10:53 +0200)
The new allocation might be in the freed area, affecting the test result.

src/libstrongswan/tests/test_chunk.c

index 5fa1c0b..4f60dab 100644 (file)
@@ -97,6 +97,7 @@ START_TEST(test_chunk_clear)
        chunk_t chunk;
        u_char *ptr;
        int i;
+       bool cleared = TRUE;
 
        chunk = chunk_empty;
        chunk_clear(&chunk);
@@ -109,12 +110,18 @@ START_TEST(test_chunk_clear)
                chunk.ptr[i] = i;
        }
        chunk_clear(&chunk);
-       assert_chunk_empty(chunk);
-       /* check memory area of freed 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++)
        {
-               ck_assert(ptr[i] == 0 || ptr[i] != i);
+               if (ptr[i] != 0 && ptr[i] == i)
+               {
+                       cleared = FALSE;
+                       break;
+               }
        }
+       assert_chunk_empty(chunk);
+       ck_assert(cleared);
 }
 END_TEST