Code

data_test: Compare return values of format() and strlen().
authorSebastian Harl <sh@tokkee.org>
Thu, 20 Feb 2014 21:52:02 +0000 (22:52 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 20 Feb 2014 21:52:02 +0000 (22:52 +0100)
This is to check that sdb_data_strlen() reports sane numbers.

t/core/data_test.c

index 4d2efedd6b5b40ead3abf98c3edfda9cf32319c1..f6f9b4826c9037d993c598f832eb894d8d7b0ed1 100644 (file)
@@ -167,6 +167,11 @@ START_TEST(test_format)
                                "sdb_data_format(type=%s) used wrong format: %s; expected: %s",
                                SDB_TYPE_TO_STRING(datum->type), buf, golden_data[i].expected);
 
+               fail_unless((size_t)check <= sizeof(buf) - 2,
+                               "sdb_data_format(type=%s) wrote %d bytes; "
+                               "expected <= %zu based on sdb_data_strlen()",
+                               SDB_TYPE_TO_STRING(datum->type), check, sizeof(buf) - 2);
+
                fail_unless(buf[sizeof(buf) - 2] == '\0',
                                "sdb_data_format(type=%s) did not nul-terminate the buffer",
                                SDB_TYPE_TO_STRING(datum->type));