[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, feature/wasted-byte, updated. gawk-4.1.0
From: |
Arnold Robbins |
Subject: |
[gawk-diffs] [SCM] gawk branch, feature/wasted-byte, updated. gawk-4.1.0-1310-gb88e0a7 |
Date: |
Mon, 13 Apr 2015 15:31:38 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".
The branch, feature/wasted-byte has been updated
via b88e0a71eaae6efb9bf4164ae095bccc07965115 (commit)
from b57630628a5c6d8d8d16f05b357f61b34c861359 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=b88e0a71eaae6efb9bf4164ae095bccc07965115
commit b88e0a71eaae6efb9bf4164ae095bccc07965115
Author: Arnold D. Robbins <address@hidden>
Date: Mon Apr 13 18:31:23 2015 +0300
Improve computations in do_sub.
diff --git a/ChangeLog b/ChangeLog
index eaab207..cff7389 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-04-14 Andrew J. Schorr <address@hidden>
+ Arnold D. Robbins <address@hidden>
+
+ * builtin.c (do_sub): Make computations smarter; initial len
+ to malloc, test for final amount after all matches done and
+ need to copy in the final part of the original string.
+
2015-04-13 Arnold D. Robbins <address@hidden>
* regcomp.c (analyze): Prevent malloc(0).
diff --git a/builtin.c b/builtin.c
index b8e2fce..3d3c1c4 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2920,8 +2920,16 @@ set_how_many:
* create the result, copying in parts of the original
* string
*/
- len = matchstart - text + repllen
- + ampersands * (matchend - matchstart);
+
+ /*
+ * add 1 to len to handle "empty" case where
+ * matchend == matchstart and we force a match on a single
+ * char. Use 'matchend - text' instead of 'matchstart - text'
+ * because we may not actually make any substitution depending
+ * on the 'global' and 'how_many' values.
+ */
+ len = matchend - text + repllen
+ + ampersands * (matchend - matchstart) + 1;
sofar = bp - buf;
while (buflen < (sofar + len + 1)) {
buflen *= 2;
@@ -3028,6 +3036,11 @@ set_how_many:
textlen = text + textlen - matchend;
text = matchend;
+#if 0
+ if (bp - buf > sofar + len)
+ fprintf(stderr, "debug: len = %zu, but used %ld\n",
len, (long)((bp - buf) - (long)sofar));
+#endif
+
if ((current >= how_many && ! global)
|| ((long) textlen <= 0 && matchstart == matchend)
|| research(rp, t->stptr, text - t->stptr, textlen,
RE_NEED_START) == -1)
@@ -3035,12 +3048,17 @@ set_how_many:
}
sofar = bp - buf;
- if (buflen - sofar - textlen - 1) {
+ if (buflen < (sofar + textlen + 1)) {
buflen = sofar + textlen + 1;
erealloc(buf, char *, buflen, "do_sub");
bp = buf + sofar;
}
- for (scan = matchend; scan < text + textlen; scan++)
+ /*
+ * Note that text == matchend, since that assignment is made before
+ * exiting the 'for' loop above. Thus we copy in the rest of the
+ * original string.
+ */
+ for (scan = text; scan < text + textlen; scan++)
*bp++ = *scan;
*bp = '\0';
textlen = bp - buf;
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 7 +++++++
builtin.c | 26 ++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, feature/wasted-byte, updated. gawk-4.1.0-1310-gb88e0a7,
Arnold Robbins <=