diff options
author | apnadkarni <apnmbx-wits@yahoo.com> | 2023-07-29 05:56:10 (GMT) |
---|---|---|
committer | apnadkarni <apnmbx-wits@yahoo.com> | 2023-07-29 05:56:10 (GMT) |
commit | a0cee2b6812330e4c021473ceb4eaf11ac87ba80 (patch) | |
tree | fc82e1f49c91fa48b39b6b8810244b3955597dd4 /generic/tclTestObj.c | |
parent | c94fa5b242a0d1a9a41fb47e1c65e76bace375dc (diff) | |
download | tcl-a0cee2b6812330e4c021473ceb4eaf11ac87ba80.zip tcl-a0cee2b6812330e4c021473ceb4eaf11ac87ba80.tar.gz tcl-a0cee2b6812330e4c021473ceb4eaf11ac87ba80.tar.bz2 |
Add tests for out of bounds Tcl_ListObjIndex
Diffstat (limited to 'generic/tclTestObj.c')
-rw-r--r-- | generic/tclTestObj.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 3b21eaf..0080938 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -893,6 +893,7 @@ TestlistobjCmd( "replace", "indexmemcheck", "getelementsmemcheck", + "index", NULL }; enum listobjCmdIndex { @@ -901,6 +902,7 @@ TestlistobjCmd( LISTOBJ_REPLACE, LISTOBJ_INDEXMEMCHECK, LISTOBJ_GETELEMENTSMEMCHECK, + LISTOBJ_INDEX, } cmdIndex; Tcl_Size varIndex; /* Variable number converted to binary */ @@ -1008,6 +1010,26 @@ TestlistobjCmd( } } break; + case LISTOBJ_INDEX: + /* + * Tcl_ListObjIndex semantics differ from lindex for out of bounds. + * Hence this explicit test. + */ + if (objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, + "varIndex listIndex"); + return TCL_ERROR; + } + if (Tcl_GetIntForIndex(interp, objv[3], TCL_INDEX_NONE, &first) != TCL_OK) { + return TCL_ERROR; + } else { + Tcl_Obj *objP; + if (Tcl_ListObjIndex(interp, varPtr[varIndex], first, &objP) != TCL_OK) { + return TCL_ERROR; + } + Tcl_SetObjResult(interp, objP ? objP : Tcl_NewStringObj("null", -1)); + } + break; } return TCL_OK; } |