diff -r 6456036bbb37 -r edb9f875b7f9 tests/test_printf.c --- a/tests/test_printf.c Wed Apr 03 21:22:23 2024 +0200 +++ b/tests/test_printf.c Fri Apr 12 21:48:12 2024 +0200 @@ -301,9 +301,11 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { char *oldbuf = buf; - size_t len = cx_sprintf_a(alloc, &buf, 16, "Test %d %s", 47, "string"); + size_t buflen = 16; + size_t len = cx_sprintf_a(alloc, &buf, &buflen, "Test %d %s", 47, "string"); CX_TEST_ASSERT(oldbuf == buf); CX_TEST_ASSERT(len == 14); + CX_TEST_ASSERT(buflen == 16); CX_TEST_ASSERT(0 == memcmp(buf, "Test 47 string", 15)); CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); } @@ -317,8 +319,10 @@ CxAllocator *alloc = &talloc.base; char *buf = cxMalloc(alloc, 8); CX_TEST_DO { - size_t len = cx_sprintf_a(alloc, &buf, 8, "Test %d %s", 47, "foobar"); + size_t buflen = 8; + size_t len = cx_sprintf_a(alloc, &buf, &buflen, "Test %d %s", 47, "foobar"); CX_TEST_ASSERT(len == 14); + CX_TEST_ASSERT(buflen == 15); CX_TEST_ASSERT(0 == memcmp(buf, "Test 47 foobar", 15)); cxFree(alloc, buf); CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); @@ -333,8 +337,10 @@ // make it so that only the zero-terminator does not fit char *buf = cxMalloc(alloc, 14); CX_TEST_DO { - size_t len = cx_sprintf_a(alloc, &buf, 14, "Test %d %s", 13, "string"); + size_t buflen = 14; + size_t len = cx_sprintf_a(alloc, &buf, &buflen, "Test %d %s", 13, "string"); CX_TEST_ASSERT(len == 14); + CX_TEST_ASSERT(buflen == 15); CX_TEST_ASSERT(0 == memcmp(buf, "Test 13 string", 15)); cxFree(alloc, buf); CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); @@ -349,8 +355,10 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { char *str; - size_t len = cx_sprintf_sa(alloc, buf, 16, &str, "Test %d %s", 47, "string"); + size_t buflen = 16; + size_t len = cx_sprintf_sa(alloc, buf, &buflen, &str, "Test %d %s", 47, "string"); CX_TEST_ASSERT(str == buf); + CX_TEST_ASSERT(buflen == 16); CX_TEST_ASSERT(len == 14); CX_TEST_ASSERT(0 == memcmp(buf, "Test 47 string", 15)); CX_TEST_ASSERT(0 == memcmp(str, "Test 47 string", 15)); @@ -367,8 +375,10 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { char *str; - size_t len = cx_sprintf_sa(alloc, buf, 16, &str, "Hello %d %s", 4711, "larger string"); + size_t buflen = 16; + size_t len = cx_sprintf_sa(alloc, buf, &buflen, &str, "Hello %d %s", 4711, "larger string"); CX_TEST_ASSERT(str != buf); + CX_TEST_ASSERT(buflen == 25); CX_TEST_ASSERT(len == 24); CX_TEST_ASSERT(0 == memcmp(str, "Hello 4711 larger string", 25)); cxFree(alloc, str); @@ -385,9 +395,11 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { char *str; - size_t len = cx_sprintf_sa(alloc, buf, 16, &str, "Hello %d %s", 112, "string"); + size_t buflen = 16; + size_t len = cx_sprintf_sa(alloc, buf,&buflen, &str, "Hello %d %s", 112, "string"); CX_TEST_ASSERT(str != buf); CX_TEST_ASSERT(len == 16); + CX_TEST_ASSERT(buflen == 17); CX_TEST_ASSERT(0 == memcmp(str, "Hello 112 string", 17)); // include terminator cxFree(alloc, str); CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));