mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-01-26 09:11:54 +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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*strp = malloc(size + 1);
|
*strp = malloc(++size);
|
||||||
if (*strp == NULL) {
|
if (*strp == NULL) {
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return -1;
|
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);
|
va_end(args);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user