diff options
author | Cody Peter Mello <melloc@writev.io> | 2018-09-15 01:38:39 -0700 |
---|---|---|
committer | Cody Peter Mello <melloc@writev.io> | 2018-09-15 01:43:21 -0700 |
commit | e26237434fb769d9c1ea239101eb5b24be588eea (patch) | |
tree | 20ade6ab596df62844ba6b4a59d169a4eecd0ab3 /run.c | |
parent | 2dc7e5ff1a4feeeb549f32706cf34e17aba89192 (diff) | |
download | one-true-awk-e26237434fb769d9c1ea239101eb5b24be588eea.tar.gz |
Fix issues with assigning during concatenation
Diffstat (limited to 'run.c')
-rw-r--r-- | run.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -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); } |