aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--NEWS3
-rw-r--r--awkgram.c10
-rw-r--r--awkgram.y10
4 files changed, 21 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index eed758ce..2c0090ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-10-12 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awkgram.y (make_profile_number): Allocate an extra byte for the
+ string, so there's room for a minus if necessary. Store '\0'
+ in the right place.
+ (negate_num): Use memmove to shift the string up and then
+ insert a minus, instead of doing a fresh alloc + copy + free.
+
2016-10-11 Arnold D. Robbins <arnold@skeeve.com>
* awk.h (NUMCONSTSTR): New flag value.
diff --git a/NEWS b/NEWS
index 7163ecff..1d844966 100644
--- a/NEWS
+++ b/NEWS
@@ -79,6 +79,9 @@ Changes from 4.1.x to 4.2.0
20. Gawk now uses fwrite_unlocked if it's available. The yields a 7% - 18%
improvement in raw output speed (gawk '{ print }' on a large file).
+21. Pretty printing now uses the original text of constant numeric values for
+ pretty printing and profiling.
+
Changes from 4.1.3 to 4.1.4
---------------------------
diff --git a/awkgram.c b/awkgram.c
index b7ad5779..2b88d3f6 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4533,11 +4533,9 @@ negate_num(NODE *n)
if ((n->flags & NUMCONSTSTR) != 0) {
char *s;
- emalloc(s, char *, n->stlen + 1 + 1, "negate_num");
+ s = n->stptr;
+ memmove(& s[1], & s[0], n->stlen + 1);
s[0] = '-';
- strcpy(& s[1], n->stptr);
- free(n->stptr);
- n->stptr = s;
n->stlen++;
}
@@ -8598,7 +8596,9 @@ make_profile_number(double d, const char *str, size_t len)
{
NODE *n = make_number(d);
if (do_pretty_print) {
- n->stptr = estrdup(str, len);
+ // extra byte in case need to add minus sign in negate_num
+ n->stptr = estrdup(str, len + 1);
+ n->stptr[len] = '\0';
n->stlen = len;
n->flags |= NUMCONSTSTR;
}
diff --git a/awkgram.y b/awkgram.y
index c81e295b..11fbd9db 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2156,11 +2156,9 @@ negate_num(NODE *n)
if ((n->flags & NUMCONSTSTR) != 0) {
char *s;
- emalloc(s, char *, n->stlen + 1 + 1, "negate_num");
+ s = n->stptr;
+ memmove(& s[1], & s[0], n->stlen + 1);
s[0] = '-';
- strcpy(& s[1], n->stptr);
- free(n->stptr);
- n->stptr = s;
n->stlen++;
}
@@ -6221,7 +6219,9 @@ make_profile_number(double d, const char *str, size_t len)
{
NODE *n = make_number(d);
if (do_pretty_print) {
- n->stptr = estrdup(str, len);
+ // extra byte in case need to add minus sign in negate_num
+ n->stptr = estrdup(str, len + 1);
+ n->stptr[len] = '\0';
n->stlen = len;
n->flags |= NUMCONSTSTR;
}