Fix issues with assigning during concatenation
This commit is contained in:
parent
2dc7e5ff1a
commit
e26237434f
@ -23,3 +23,8 @@ and also if CONVFMT changed.
|
|||||||
|
|
||||||
7. unary-plus: Unary plus on a string constant returned the string.
|
7. unary-plus: Unary plus on a string constant returned the string.
|
||||||
Instead, it should convert the value to numeric and give that value.
|
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".
|
||||||
|
4
bugs-fixed/concat-assign-same.awk
Normal file
4
bugs-fixed/concat-assign-same.awk
Normal 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);
|
||||||
|
}
|
2
bugs-fixed/concat-assign-same.bad
Normal file
2
bugs-fixed/concat-assign-same.bad
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
22345
|
||||||
|
1 2 3 4 5
|
2
bugs-fixed/concat-assign-same.ok
Normal file
2
bugs-fixed/concat-assign-same.ok
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
12345
|
||||||
|
1 2 3 4 5
|
23
run.c
23
run.c
@ -1175,25 +1175,26 @@ Cell *cat(Node **a, int q) /* a[0] cat a[1] */
|
|||||||
{
|
{
|
||||||
Cell *x, *y, *z;
|
Cell *x, *y, *z;
|
||||||
int n1, n2;
|
int n1, n2;
|
||||||
char *s;
|
char *s = NULL;
|
||||||
|
int ssz = 0;
|
||||||
|
|
||||||
x = execute(a[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]);
|
y = execute(a[1]);
|
||||||
getsval(x);
|
n2 = strlen(getsval(y));
|
||||||
getsval(y);
|
adjbuf(&s, &ssz, n1 + n2 + 1, recsize, 0, "cat2");
|
||||||
n1 = strlen(x->sval);
|
(void) strncpy(s + n1, y->sval, ssz - n1);
|
||||||
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);
|
|
||||||
tempfree(x);
|
tempfree(x);
|
||||||
tempfree(y);
|
tempfree(y);
|
||||||
|
|
||||||
z = gettemp();
|
z = gettemp();
|
||||||
z->sval = s;
|
z->sval = s;
|
||||||
z->tval = STR;
|
z->tval = STR;
|
||||||
|
|
||||||
return(z);
|
return(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user