aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-08-13 06:32:25 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-08-13 06:32:25 +0300
commit9d8bd17c58e8fc74d4ad80b199d5ea1d5cbd2bce (patch)
tree66bc0f0fa02973f1111cade3fc7c291f5da71256 /builtin.c
parent9e2907afe246b3930d9ae6043a2657c4492f4507 (diff)
parent1059680510215830da7e2eb91e72e4623d460d19 (diff)
downloadegawk-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.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/builtin.c b/builtin.c
index 778760d9..934664b0 100644
--- a/builtin.c
+++ b/builtin.c
@@ -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++;