diff options
author | dkf <dkf@noemail.net> | 2011-09-26 10:09:11 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2011-09-26 10:09:11 (GMT) |
commit | f9b1f712c7c197408279ba6ee90d81f5e5697d47 (patch) | |
tree | 01ed668a0cba032c40c4bb0537cf9e72887d9372 /generic/tclIndexObj.c | |
parent | e369109c668fd5df537e0395e88a8719365a1a1a (diff) | |
download | tcl-f9b1f712c7c197408279ba6ee90d81f5e5697d47.zip tcl-f9b1f712c7c197408279ba6ee90d81f5e5697d47.tar.gz tcl-f9b1f712c7c197408279ba6ee90d81f5e5697d47.tar.bz2 |
Proposed patch to fix [Bug 3413857]...
FossilOrigin-Name: 8edb5ef770d0de1f32ba001970f32a71554f1197
Diffstat (limited to 'generic/tclIndexObj.c')
-rw-r--r-- | generic/tclIndexObj.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index 6f378a4..4e04f71 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -1113,13 +1113,15 @@ Tcl_ParseArgsObjv( if (remObjv != NULL) { /* - * Then we should copy the name of the command (0th argument). + * Then we should copy the name of the command (0th argument). The + * upper bound on the number of elements is known, and (undocumented, + * but historically true) there should be a NULL argument after the + * last result. [Bug 3413857] */ nrem = 1; - leftovers = ckalloc((nrem + 1) * sizeof(Tcl_Obj *)); - leftovers[nrem-1] = objv[0]; - leftovers[nrem] = NULL; + leftovers = ckalloc((1 + *objcPtr) * sizeof(Tcl_Obj *)); + leftovers[0] = objv[0]; } else { nrem = 0; leftovers = NULL; @@ -1182,14 +1184,7 @@ Tcl_ParseArgsObjv( } dstIndex++; /* This argument is now handled */ - nrem++; - - /* - * Allocate nrem (+1 extra for NULL terminator) pointers. - */ - - leftovers = ckrealloc(leftovers, (nrem+1) * sizeof(Tcl_Obj *)); - leftovers[nrem-1] = curArg; + leftovers[nrem++] = curArg; continue; } @@ -1282,7 +1277,9 @@ Tcl_ParseArgsObjv( /* * If we broke out of the loop because of an OPT_REST argument, copy the - * remaining arguments down. + * remaining arguments down. Note that there is always at least one + * argument left over - the command name - so we always have a result if + * our caller is willing to receive it. [Bug 3413857] */ argsDone: @@ -1295,19 +1292,12 @@ Tcl_ParseArgsObjv( } if (objc > 0) { - leftovers = ckrealloc(leftovers, (nrem+objc+1) * sizeof(Tcl_Obj *)); - while (objc) { - leftovers[nrem] = objv[srcIndex]; - nrem++; - srcIndex++; - objc--; - } - } else if (leftovers != NULL) { - ckfree(leftovers); + memcpy(leftovers+nrem, objv+srcIndex, objc*sizeof(Tcl_Obj *)); + nrem += objc; } leftovers[nrem] = NULL; - *objcPtr = nrem; - *remObjv = leftovers; + *objcPtr = nrem++; + *remObjv = ckrealloc(leftovers, nrem * sizeof(Tcl_Obj *)); return TCL_OK; /* |