From cde36888a3577af5d0807b970f73d480ee0c72a1 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sun, 28 Jan 2024 13:41:49 +0300 Subject: [PATCH] asprintf.c: optimize `size + 1` with fixup applied --- c-programming/asprintf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c-programming/asprintf.c b/c-programming/asprintf.c index 4d5dee6..4dbdda5 100644 --- a/c-programming/asprintf.c +++ b/c-programming/asprintf.c @@ -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) {