mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-11-09 21:32:02 +05:30
asprintf.c: optimize size + 1
with fixup applied
This commit is contained in:
parent
f98cbbaf84
commit
cde36888a3
@ -17,13 +17,13 @@ ssize_t asprintf(char** strp, char* format, ...) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*strp = malloc(size + 1);
|
||||
*strp = malloc(++size);
|
||||
if (*strp == NULL) {
|
||||
va_end(args);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t result = (ssize_t) vsnprintf(*strp, size + 1, format, args);
|
||||
ssize_t result = (ssize_t) vsnprintf(*strp, size, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (result < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user