diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2019-08-30 12:57:21 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2019-08-30 12:57:21 +0300 |
commit | 134f9d04acffcd68c298a7f41419b0620212595e (patch) | |
tree | 8b57d66071f1312ec6bfe9236871385cec50d2e0 /builtin.c | |
parent | 58982af68e8cbbc71b48a2ab36865ed4630b960b (diff) | |
download | egawk-134f9d04acffcd68c298a7f41419b0620212595e.tar.gz egawk-134f9d04acffcd68c298a7f41419b0620212595e.tar.bz2 egawk-134f9d04acffcd68c298a7f41419b0620212595e.zip |
Restore modified use of realloc in format_tree.
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -685,7 +685,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; @@ -735,7 +735,7 @@ format_tree( static const char lchbuf[] = "0123456789abcdef"; static const char Uchbuf[] = "0123456789ABCDEF"; -#define INITIAL_OUT_SIZE 512 +#define INITIAL_OUT_SIZE 64 emalloc(obuf, char *, INITIAL_OUT_SIZE, "format_tree"); obufout = obuf; osiz = INITIAL_OUT_SIZE; @@ -1646,7 +1646,11 @@ 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; +#define GIVE_BACK_SIZE (INITIAL_OUT_SIZE * 2) + if (ofre > GIVE_BACK_SIZE) + erealloc(obuf, char *, olen_final + 1, "format_tree"); + r = make_str_node(obuf, olen_final, ALREADY_MALLOCED); obuf = NULL; out: { |