Skip to content

Commit f60e164

Browse files
author
jan.nijtmans
committed
Make it impossible for the indexType object to cache negative index values. And - if it happens - at least don't crash on it.
1 parent a128b4d commit f60e164

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

generic/tclIndexObj.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ typedef struct {
7373
#define NEXT_ENTRY(table, offset) \
7474
(&(STRING_AT(table, offset)))
7575
#define EXPAND_OF(indexRep) \
76-
STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index)
76+
(((indexRep)->index >= 0) ? STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index) : "")
7777

7878
/*
7979
*----------------------------------------------------------------------
@@ -280,7 +280,9 @@ Tcl_GetIndexFromObjStruct(
280280

281281
if (objPtr && (objPtr->typePtr == &indexType)) {
282282
indexRep = objPtr->internalRep.twoPtrValue.ptr1;
283-
if (indexRep->tablePtr==tablePtr && indexRep->offset==offset) {
283+
if ((indexRep->tablePtr == tablePtr)
284+
&& (indexRep->offset == offset)
285+
&& (indexRep->index >= 0)) {
284286
*indexPtr = indexRep->index;
285287
return TCL_OK;
286288
}
@@ -339,7 +341,7 @@ Tcl_GetIndexFromObjStruct(
339341
* operation.
340342
*/
341343

342-
if (objPtr) {
344+
if (objPtr && (index >= 0)) {
343345
if (objPtr->typePtr == &indexType) {
344346
indexRep = objPtr->internalRep.twoPtrValue.ptr1;
345347
} else {

0 commit comments

Comments
 (0)