1
0
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:
Intel A80486DX2-66 2024-01-28 13:41:49 +03:00
parent f98cbbaf84
commit cde36888a3
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -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) {