changeset 362:a688d34c11d4

Sanitize test_snprintf().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 25 Feb 2016 11:59:06 +0200
parents ad9719373fe3
children 68e8ad3327b8
files tests.c
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Thu Feb 25 11:53:08 2016 +0200
+++ b/tests.c	Thu Feb 25 11:59:06 2016 +0200
@@ -205,18 +205,13 @@
     test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]);
     test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]);
 
-    // Test th_strdup_vprintf()
-    test_start(&ctx, "th_strdup_vprintf('%s')", fmt);
-    va_copy(tmp, ap);
-    char *str = th_strdup_vprintf(fmt, tmp);
-    test_result_msg(&ctx, str != NULL, "result NULL");
-    th_free(str);
     test_end(&ctx);
 }
 
 
 void test_snprintf(const char *msg, const char *fmt, ...)
 {
+    test_ctx ctx;
     va_list ap, tmp;
     va_start(ap, fmt);
     va_copy(tmp, ap); test_snprintf_do(0, msg, fmt, tmp);
@@ -224,6 +219,16 @@
     va_copy(tmp, ap); test_snprintf_do(2, msg, fmt, tmp);
     va_copy(tmp, ap); test_snprintf_do(16, msg, fmt, tmp);
     va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, msg, fmt, tmp);
+
+    // Test th_strdup_vprintf()
+    test_init(&ctx);
+    test_start(&ctx, "th_strdup_vprintf('%s')", fmt);
+    va_copy(tmp, ap);
+    char *str = th_strdup_vprintf(fmt, tmp);
+    test_result_msg(&ctx, str != NULL, "result NULL");
+    th_free(str);
+    test_end(&ctx);
+
     va_end(ap); 
     tprint(2,
         "-----------------------------------------------------\n");