ref: 905d26010499d090ba9dac06cdd876f1ea2887e0
parent: f70e36869ea55f9c19d328d4e910fa6a8d77d6da
parent: 1d836ff681967fa858902f2328f2dda83848cc23
author: onetrueawk <bwkster@gmail.com>
date: Mon Jan 21 09:17:19 EST 2019
Merge pull request #16 from melloc/assign-expr Fix issues with assigning during concatenation
--- a/bugs-fixed/README
+++ b/bugs-fixed/README
@@ -24,11 +24,18 @@
7. unary-plus: Unary plus on a string constant returned the string.
Instead, it should convert the value to numeric and give that value.
-8. missing-precision: When using the format string "%*s", the precision
+8. concat-assign-same: Concatenation previously evaluated both sides of the
+expression before doing its work, which, since assign() evaluates to the cell
+being assigned to, meant that expressions like "print (a = 1) (a = 2)" would
+print "22" rather than "12".
+
+9. missing-precision: When using the format string "%*s", the precision
argument was used without checking if it was present first.
-9. fmt-overflow: The buffer used for OFMT/CONVFMT conversions was written
+10. missing-precision: When using the format string "%*s", the precision
+argument was used without checking if it was present first.
+
+11. fmt-overflow: The buffer used for OFMT/CONVFMT conversions was written
to with sprintf(), which meant that some conversions could write past the
end.
-
--- /dev/null
+++ b/bugs-fixed/concat-assign-same.awk
@@ -1,0 +1,4 @@
+BEGIN {+ print (a = 1) (a = 2) (a = 3) (a = 4) (a = 5);
+ print (a = 1), (a = 2), (a = 3), (a = 4), (a = 5);
+}
--- /dev/null
+++ b/bugs-fixed/concat-assign-same.bad
@@ -1,0 +1,2 @@
+22345
+1 2 3 4 5
--- /dev/null
+++ b/bugs-fixed/concat-assign-same.ok
@@ -1,0 +1,2 @@
+12345
+1 2 3 4 5
--- a/run.c
+++ b/run.c
@@ -1178,25 +1178,26 @@
{Cell *x, *y, *z;
int n1, n2;
- char *s;
+ char *s = NULL;
+ int ssz = 0;
x = execute(a[0]);
+ n1 = strlen(getsval(x));
+ adjbuf(&s, &ssz, n1 + 1, recsize, 0, "cat1");
+ (void) strncpy(s, x->sval, ssz);
+
y = execute(a[1]);
- getsval(x);
- getsval(y);
- n1 = strlen(x->sval);
- n2 = strlen(y->sval);
- s = (char *) malloc(n1 + n2 + 1);
- if (s == NULL)
- FATAL("out of space concatenating %.15s... and %.15s...",- x->sval, y->sval);
- strcpy(s, x->sval);
- strcpy(s+n1, y->sval);
+ n2 = strlen(getsval(y));
+ adjbuf(&s, &ssz, n1 + n2 + 1, recsize, 0, "cat2");
+ (void) strncpy(s + n1, y->sval, ssz - n1);
+
tempfree(x);
tempfree(y);
+
z = gettemp();
z->sval = s;
z->tval = STR;
+
return(z);
}
--
⑨