diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | builtin.c | 7 |
2 files changed, 12 insertions, 2 deletions
@@ -1,3 +1,10 @@ +2016-05-03 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * builtin.c (format_tree): After the string has been rendered, use + realloc to shrink the buffer to the needed size. Otherwise, the minimum + buffer size of 512 bytes can result in lots of wasted memory if many + sprintf results are stored in an array. + 2016-05-02 Andrew J. Schorr <aschorr@telemetry-investments.com> * gawkapi.h (gawk_api_major_version, gawk_api_minor_version): Add @@ -660,7 +660,7 @@ format_tree( int i, nc; bool toofew = false; char *obuf, *obufout; - size_t osiz, ofre; + size_t osiz, ofre, olen_final; const char *chbuf; const char *s0, *s1; int cs1; @@ -1572,7 +1572,10 @@ mpf1: _("too many arguments supplied for format string")); } bchunk(s0, s1 - s0); - r = make_str_node(obuf, obufout - obuf, ALREADY_MALLOCED); + olen_final = obufout - obuf; + if (ofre > 0) + erealloc(obuf, char *, olen_final + 2, "format_tree"); + r = make_str_node(obuf, olen_final, ALREADY_MALLOCED); obuf = NULL; out: { |