tangled
alpha
login
or
join now
bernsteinbear.com
/
fmt
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
Bail early on allocation failure
bernsteinbear.com
3 years ago
d06adc8f
227edcf3
+5
1 changed file
expand all
collapse all
unified
split
fmt.h
+5
fmt.h
reviewed
···
11
11
size_t length;
12
12
} str_size;
13
13
14
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
26
+
if (result.str == NULL) {
27
27
+
return result;
28
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
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;