diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-12-18 18:55:50 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-12-18 18:55:50 (GMT) |
commit | f60e1647996f8494c8eb64899086f74a43dc0120 (patch) | |
tree | e2b16afab77365cfd26b76ebfc8f0ba41f674253 /generic | |
parent | a128b4d651075c9263df3e8959beaac5a403e54d (diff) | |
download | tcl-f60e1647996f8494c8eb64899086f74a43dc0120.zip tcl-f60e1647996f8494c8eb64899086f74a43dc0120.tar.gz tcl-f60e1647996f8494c8eb64899086f74a43dc0120.tar.bz2 |
Make it impossible for the indexType object to cache negative index values. And - if it happens - at least don't crash on it.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclIndexObj.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index efa7373..8911f00 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -73,7 +73,7 @@ typedef struct { #define NEXT_ENTRY(table, offset) \ (&(STRING_AT(table, offset))) #define EXPAND_OF(indexRep) \ - STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index) + (((indexRep)->index >= 0) ? STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index) : "") /* *---------------------------------------------------------------------- @@ -280,7 +280,9 @@ Tcl_GetIndexFromObjStruct( if (objPtr && (objPtr->typePtr == &indexType)) { indexRep = objPtr->internalRep.twoPtrValue.ptr1; - if (indexRep->tablePtr==tablePtr && indexRep->offset==offset) { + if ((indexRep->tablePtr == tablePtr) + && (indexRep->offset == offset) + && (indexRep->index >= 0)) { *indexPtr = indexRep->index; return TCL_OK; } @@ -339,7 +341,7 @@ Tcl_GetIndexFromObjStruct( * operation. */ - if (objPtr) { + if (objPtr && (index >= 0)) { if (objPtr->typePtr == &indexType) { indexRep = objPtr->internalRep.twoPtrValue.ptr1; } else { |