We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 443cd53 commit 6ece227Copy full SHA for 6ece227
1 file changed
src/csprintf_s.h
@@ -29,16 +29,23 @@
29
#include <stdio.h>
30
31
char* csprintf_s(char* format, ...) {
32
- va_list args;
33
- va_start(args, format);
34
-
35
- int buffSz = vsnprintf(NULL, 0, format, args);
36
37
- char* buff = (char*) malloc(buffSz + 1);
38
- vsnprintf(buff, buffSz + 1, format, args);
39
40
- va_end(args);
41
42
- 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) {
+ vsnprintf(buff, buffSz + 1, format, args);
43
44
45
+ return buff;
46
+ } else
47
+ return NULL;
48
49
50
}
51
#endif
0 commit comments