diff options
Diffstat (limited to 'man3/printf.3')
| -rw-r--r-- | man3/printf.3 | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/man3/printf.3 b/man3/printf.3 index 50e136ba60..827d9cbae6 100644 --- a/man3/printf.3 +++ b/man3/printf.3 @@ -1132,29 +1132,32 @@ To allocate a sufficiently large string and print into it char * make_message(const char *fmt, ...) { - int size = 0; + int n = 0; + size_t size = 0; char *p = NULL; va_list ap; /* Determine required size */ va_start(ap, fmt); - size = vsnprintf(p, size, fmt, ap); + n = vsnprintf(p, size, fmt, ap); va_end(ap); - if (size < 0) + if (n < 0) return NULL; - size++; /* For '\e0' */ + /* One extra byte for '\e0' */ + + size = (size_t) n + 1; p = malloc(size); if (p == NULL) return NULL; va_start(ap, fmt); - size = vsnprintf(p, size, fmt, ap); + n = vsnprintf(p, size, fmt, ap); va_end(ap); - if (size < 0) { + if (n < 0) { free(p); return NULL; } |
