Fix issues with assigning during concatenation

This commit is contained in:
Cody Peter Mello 2018-09-15 01:38:39 -07:00
parent 2dc7e5ff1a
commit e26237434f
5 changed files with 25 additions and 11 deletions

View File

@ -23,3 +23,8 @@ and also if CONVFMT changed.
7. unary-plus: Unary plus on a string constant returned the string.
Instead, it should convert the value to numeric and give that value.
X. 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".

View File

@ -0,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);
}

View File

@ -0,0 +1,2 @@
22345
1 2 3 4 5

View File

@ -0,0 +1,2 @@
12345
1 2 3 4 5

23
run.c
View File

@ -1175,25 +1175,26 @@ Cell *cat(Node **a, int q) /* a[0] cat a[1] */
{
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);
}