Skip to content

Commit

Permalink
Fix reusal of va_list
Browse files Browse the repository at this point in the history
  • Loading branch information
xchellx committed Aug 29, 2022
1 parent 443cd53 commit 6ece227
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/csprintf_s.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@
#include <stdio.h>

char* csprintf_s(char* format, ...) {
va_list args;
va_start(args, format);

int buffSz = vsnprintf(NULL, 0, format, args);

char* buff = (char*) malloc(buffSz + 1);
vsnprintf(buff, buffSz + 1, format, args);

va_end(args);

return buff;
if (format != NULL) {
va_list args;

va_start(args, format);
int buffSz = vsnprintf(NULL, 0, format, args);
va_end(args);

char* buff = (char*) malloc(buffSz + 1);
if (buff != NULL) {
va_start(args, format);
vsnprintf(buff, buffSz + 1, format, args);
va_end(args);

return buff;
} else
return NULL;
} else
return NULL;
}
#endif

0 comments on commit 6ece227

Please sign in to comment.