Merge pull request #19 from melloc/split-fs-from-array
Fix calling split() with a third argument that lives in the target array
This commit is contained in:
commit
c154c3cb82
|
@ -46,3 +46,8 @@ wouldn't always be generated before being needed.
|
||||||
13. subsep-overflow: The length of SUBSEP needs to be rechecked after
|
13. subsep-overflow: The length of SUBSEP needs to be rechecked after
|
||||||
calling execute(), in case SUBSEP itself has been changed.
|
calling execute(), in case SUBSEP itself has been changed.
|
||||||
|
|
||||||
|
14. split-fs-from-array: If the third argument to split() comes from the
|
||||||
|
array passed as the second argument, then split() would previously read
|
||||||
|
from the freed memory and possibly produce incorrect results (depending
|
||||||
|
on the system's malloc()/free() behaviour.)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
BEGIN {
|
||||||
|
a[1] = "elephantie"
|
||||||
|
a[2] = "e"
|
||||||
|
print split(a[1],a,a[2]), a[2], a[3], split(a[2],a,a[2])
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
4 l phanti 2
|
10
run.c
10
run.c
|
@ -1247,8 +1247,9 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
|
||||||
{
|
{
|
||||||
Cell *x = 0, *y, *ap;
|
Cell *x = 0, *y, *ap;
|
||||||
char *s, *origs;
|
char *s, *origs;
|
||||||
|
char *fs, *origfs = NULL;
|
||||||
int sep;
|
int sep;
|
||||||
char *t, temp, num[50], *fs = 0;
|
char *t, temp, num[50];
|
||||||
int n, tempstat, arg3type;
|
int n, tempstat, arg3type;
|
||||||
|
|
||||||
y = execute(a[0]); /* source string */
|
y = execute(a[0]); /* source string */
|
||||||
|
@ -1258,7 +1259,8 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
|
||||||
fs = getsval(fsloc);
|
fs = getsval(fsloc);
|
||||||
else if (arg3type == STRING) { /* split(str,arr,"string") */
|
else if (arg3type == STRING) { /* split(str,arr,"string") */
|
||||||
x = execute(a[2]);
|
x = execute(a[2]);
|
||||||
fs = getsval(x);
|
origfs = fs = strdup(getsval(x));
|
||||||
|
tempfree(x);
|
||||||
} else if (arg3type == REGEXPR)
|
} else if (arg3type == REGEXPR)
|
||||||
fs = "(regexpr)"; /* split(str,arr,/regexpr/) */
|
fs = "(regexpr)"; /* split(str,arr,/regexpr/) */
|
||||||
else
|
else
|
||||||
|
@ -1373,9 +1375,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
|
||||||
tempfree(ap);
|
tempfree(ap);
|
||||||
tempfree(y);
|
tempfree(y);
|
||||||
free(origs);
|
free(origs);
|
||||||
if (a[2] != 0 && arg3type == STRING) {
|
free(origfs);
|
||||||
tempfree(x);
|
|
||||||
}
|
|
||||||
x = gettemp();
|
x = gettemp();
|
||||||
x->tval = NUM;
|
x->tval = NUM;
|
||||||
x->fval = n;
|
x->fval = n;
|
||||||
|
|
Loading…
Reference in New Issue