aboutsummaryrefslogtreecommitdiff
path: root/run.c
diff options
context:
space:
mode:
authorCody Peter Mello <melloc@writev.io>2018-09-15 01:38:39 -0700
committerCody Peter Mello <melloc@writev.io>2018-09-15 01:43:21 -0700
commite26237434fb769d9c1ea239101eb5b24be588eea (patch)
tree20ade6ab596df62844ba6b4a59d169a4eecd0ab3 /run.c
parent2dc7e5ff1a4feeeb549f32706cf34e17aba89192 (diff)
downloadone-true-awk-e26237434fb769d9c1ea239101eb5b24be588eea.tar.gz
Fix issues with assigning during concatenation
Diffstat (limited to 'run.c')
-rw-r--r--run.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/run.c b/run.c
index 81b75da..14b0e21 100644
--- a/run.c
+++ b/run.c
@@ -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);
}