1 Reduce the initial buffer size for open_memstream (used by vasprintf),
2 as most strings are usually smaller than that.
3 Realloc the buffer after finishing the string to further reduce size.
5 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
7 --- a/libc/stdio/vasprintf.c
8 +++ b/libc/stdio/vasprintf.c
9 @@ -39,6 +39,8 @@ int vasprintf(char **__restrict buf, con
14 + *buf = realloc(*buf, rv + 1);
18 --- a/libc/stdio/open_memstream.c
19 +++ b/libc/stdio/open_memstream.c
22 #define COOKIE ((__oms_cookie *) cookie)
24 +#define MEMSTREAM_BUFSIZ 256
29 @@ -134,7 +136,7 @@ FILE *open_memstream(char **__restrict b
32 if ((cookie = malloc(sizeof(__oms_cookie))) != NULL) {
33 - if ((cookie->buf = malloc(cookie->len = BUFSIZ)) == NULL) {
34 + if ((cookie->buf = malloc(cookie->len = MEMSTREAM_BUFSIZ)) == NULL) {
37 *cookie->buf = 0; /* Set nul terminator for buffer. */