this repo has no description

Bail early on allocation failure

+5
+5
fmt.h
··· 11 11 size_t length; 12 12 } str_size; 13 13 14 + // Returns NULL str if allocation or formatting fails. 14 15 static str_size formatv(const char *fmt, va_list args) { 15 16 va_list args_copy; 16 17 va_copy(args_copy, args); ··· 22 23 result.length = (size_t)size; 23 24 // +1 to include NUL 24 25 result.str = malloc(size + 1); 26 + if (result.str == NULL) { 27 + return result; 28 + } 25 29 vsnprintf(result.str, size + 1, fmt, args_copy); 26 30 va_end(args_copy); 27 31 return result; 28 32 } 29 33 34 + // Returns NULL str if allocation or formatting fails. 30 35 __attribute__((format(printf, 1, 2))) static str_size format(const char *fmt, 31 36 ...) { 32 37 va_list args;