]> git.codecow.com Git - Monocypher.git/commitdiff
Fixed small undefined behaviour in tests
authorLoup Vaillant <loup@loup-vaillant.fr>
Sun, 28 Jan 2018 23:36:24 +0000 (00:36 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sun, 28 Jan 2018 23:36:24 +0000 (00:36 +0100)
Apparently we cannot memcmp() null pointers, even when the size is zero.

tests/test.c

index c14010981526e6805e6a396d9e8fe327bf8eac90..9830591f7a38d4ec7af045784c1e8918ffb8b4b2 100644 (file)
@@ -64,7 +64,9 @@ static int test(void (*f)(const vector[], vector*),
         expected.buf  = vectors[idx+nb_inputs];
         expected.size = sizes  [idx+nb_inputs];
         status |= out.size - expected.size;
-        status |= memcmp(out.buf, expected.buf, out.size);
+        if (out.size != 0) {
+            status |= memcmp(out.buf, expected.buf, out.size);
+        }
         free(out.buf);
         idx += nb_inputs + 1;
         nb_tests++;