diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-13 06:32:25 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-13 06:32:25 +0300 |
commit | 9d8bd17c58e8fc74d4ad80b199d5ea1d5cbd2bce (patch) | |
tree | 66bc0f0fa02973f1111cade3fc7c291f5da71256 /builtin.c | |
parent | 9e2907afe246b3930d9ae6043a2657c4492f4507 (diff) | |
parent | 1059680510215830da7e2eb91e72e4623d460d19 (diff) | |
download | egawk-9d8bd17c58e8fc74d4ad80b199d5ea1d5cbd2bce.tar.gz egawk-9d8bd17c58e8fc74d4ad80b199d5ea1d5cbd2bce.tar.bz2 egawk-9d8bd17c58e8fc74d4ad80b199d5ea1d5cbd2bce.zip |
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -2847,16 +2847,11 @@ set_how_many: text = t->stptr; textlen = t->stlen; - buflen = textlen + 2; repl = s->stptr; replend = repl + s->stlen; repllen = replend - repl; - emalloc(buf, char *, buflen + 2, "do_sub"); - buf[buflen] = '\0'; - buf[buflen + 1] = '\0'; - ampersands = 0; /* @@ -2915,6 +2910,13 @@ set_how_many: } lastmatchnonzero = false; + + /* guesstimate how much room to allocate; +2 forces > 0 */ + buflen = textlen + (ampersands + 1) * repllen + 2; + emalloc(buf, char *, buflen + 2, "do_sub"); + buf[buflen] = '\0'; + buf[buflen + 1] = '\0'; + bp = buf; for (current = 1;; current++) { matches++; |