#include #include static void vsnprintf_test(char **str, size_t *alloc_len, size_t *offset, const char *fmt, ...) { va_list args; if (NULL == *str) { va_start(args, fmt); printf("Calling vsnprintf()\n"); *alloc_len = vsnprintf(NULL, 0, fmt, args) + 2; /* '\0' + one byte to prevent the operation retry */ printf("After vsnprintf()\n"); va_end(args); *offset = 0; } } int main(void) { char *msg = NULL; size_t msg_alloc = 0, msg_offset = 0; vsnprintf_test(&msg, &msg_alloc, &msg_offset, "%s", "ABC"); }