Skip to content

Commit

Permalink
issue #25: fix this modify crash
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 10777e7a64996c61fceb96e383fbdc35637693331d24576b1da5af8f188f8cdf
  • Loading branch information
pmacdona committed Oct 22, 2020
1 parent 34a5fc3 commit f6ef9e8
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/jsiArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,12 @@ static Jsi_RC jsi_ArrayMapCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_t
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vobjs[2] = Jsi_ValueNewObj(interp, obj);
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Jsi_IncrRefCount(interp, vobjs[2]);
nobj->arr[i] = Jsi_ValueNew1(interp);
Jsi_DecrRefCount(interp, vobjs[2]);
rc = Jsi_FunctionInvoke(interp, func, vpargs, nobj->arr+i, sthis);
Jsi_DecrRefCount(interp, vpargs);
}
Expand Down Expand Up @@ -433,11 +435,13 @@ static Jsi_RC jsi_ArrayFilterCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vobjs[2] = Jsi_ValueNewObj(interp, obj);
Jsi_IncrRefCount(interp, vobjs[2]);
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
rc = Jsi_FunctionInvoke(interp, func, vpargs, &nrPtr, sthis);
Jsi_DecrRefCount(interp, vpargs);
Jsi_DecrRefCount(interp, vobjs[2]);
fval = Jsi_ValueIsTrue(interp, nrPtr);
if( JSI_OK!=rc ) {
goto bail;
Expand Down Expand Up @@ -520,10 +524,12 @@ static Jsi_RC jsi_ArrayForeachCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vobjs[2] = Jsi_ValueNewObj(interp, obj);
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Jsi_IncrRefCount(interp, vobjs[2]);
rc = Jsi_FunctionInvoke(interp, func, vpargs, ret, sthis);
Jsi_DecrRefCount(interp, vobjs[2]);
Jsi_DecrRefCount(interp, vpargs);
}
Jsi_DecrRefCount(interp, _this);
Expand Down Expand Up @@ -563,11 +569,13 @@ static Jsi_RC jsi_ArrayFindSubCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vobjs[2] = Jsi_ValueNewObj(interp, obj);
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vobjs[2]);
Jsi_IncrRefCount(interp, vpargs);
rc = Jsi_FunctionInvoke(interp, func, vpargs, &nrPtr, sthis);
Jsi_DecrRefCount(interp, vpargs);
Jsi_DecrRefCount(interp, vobjs[2]);
if (rc != JSI_OK)
break;
fval = Jsi_ValueIsTrue(interp, nrPtr);
Expand Down Expand Up @@ -609,14 +617,14 @@ static Jsi_RC jsi_ArrayReduceSubCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Val
obj = _this->d.obj;
Jsi_ObjListifyArray(interp, obj);
Jsi_Value *vobjs[4];
int n, rev = (op==2);
int n, rev = (op==2), start = 0, end = obj->arrCnt-1;
Jsi_Func *fptr = func->d.obj->d.fobj->func;
int maa = (fptr->argnames?fptr->argnames->argCnt:0);
if (maa>4 || fptr->type == FC_BUILDIN)
maa = 4;

Jsi_IncrRefCount(interp, _this);
for (n = 0, i = (rev?obj->arrCnt-1:0); (rev?i>=0:i < (int)obj->arrCnt) && rc == JSI_OK; n++, i = (rev?i-1:i+1)) {
for (n = 0, i = (rev?end:start); (rev?i>=start:i<=end) && rc == JSI_OK; n++, i += (rev?-1:1)) {
if (!obj->arr[i]) continue;
if (n==0 && !ini) {
ini = obj->arr[i];
Expand All @@ -626,11 +634,13 @@ static Jsi_RC jsi_ArrayReduceSubCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Val
vobjs[0] = ini;
vobjs[1] = obj->arr[i];
vobjs[2] = (maa>2?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[3] = _this;
vobjs[3] = Jsi_ValueNewObj(interp, obj);
Jsi_IncrRefCount(interp, vobjs[3]);
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
rc = Jsi_FunctionInvoke(interp, func, vpargs, &nrPtr, _this);
Jsi_DecrRefCount(interp, vpargs);
Jsi_DecrRefCount(interp, vobjs[3]);
if (rc != JSI_OK)
break;
ini = nrPtr;
Expand Down

0 comments on commit f6ef9e8

Please sign in to comment.