# HG changeset patch # User Matti Hamalainen # Date 1456394346 -7200 # Node ID a688d34c11d4ebf6973fe35c2dc4bd289414a5cd # Parent ad9719373fe37d284d68144e803f1e2e43ee11c4 Sanitize test_snprintf(). diff -r ad9719373fe3 -r a688d34c11d4 tests.c --- 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");