118
118
/*
119
119
* Prototypes for non-inline static functions defined later in this file:
120
120
*/
121
- static int MemoryAllocationError (Tcl_Interp * , Tcl_Size size );
121
+ static int MemoryAllocationError (Tcl_Interp * , size_t size );
122
122
static int ListLimitExceededError (Tcl_Interp * );
123
123
static ListStore * ListStoreNew (Tcl_Size objc , Tcl_Obj * const objv [], int flags );
124
124
static int ListRepInit (Tcl_Size objc , Tcl_Obj * const objv [], int flags , ListRep * );
@@ -463,15 +463,15 @@ ObjArrayCopy(
463
463
static int
464
464
MemoryAllocationError (
465
465
Tcl_Interp * interp , /* Interpreter for error message. May be NULL */
466
- Tcl_Size size ) /* Size of attempted allocation that failed */
466
+ size_t size ) /* Size of attempted allocation that failed */
467
467
{
468
468
if (interp != NULL ) {
469
469
Tcl_SetObjResult (
470
470
interp ,
471
471
Tcl_ObjPrintf (
472
- "list construction failed: unable to alloc %" TCL_LL_MODIFIER
472
+ "list construction failed: unable to alloc %" TCL_Z_MODIFIER
473
473
"u bytes" ,
474
- ( Tcl_WideInt ) size ));
474
+ size ));
475
475
Tcl_SetErrorCode (interp , "TCL" , "MEMORY" , NULL );
476
476
}
477
477
return TCL_ERROR ;
@@ -642,8 +642,11 @@ ListRepValidate(const ListRep *repPtr, const char *file, int lineNum)
642
642
643
643
/* Separate each condition so line number gives exact reason for failure */
644
644
INVARIANT (storePtr != NULL );
645
+ INVARIANT (storePtr -> numAllocated >= 0 );
645
646
INVARIANT (storePtr -> numAllocated <= LIST_MAX );
647
+ INVARIANT (storePtr -> firstUsed >= 0 );
646
648
INVARIANT (storePtr -> firstUsed < storePtr -> numAllocated );
649
+ INVARIANT (storePtr -> numUsed >= 0 );
647
650
INVARIANT (storePtr -> numUsed <= storePtr -> numAllocated );
648
651
INVARIANT (storePtr -> firstUsed <= (storePtr -> numAllocated - storePtr -> numUsed ));
649
652
@@ -754,9 +757,9 @@ ListStoreNew(
754
757
}
755
758
if (storePtr == NULL ) {
756
759
if (flags & LISTREP_PANIC_ON_FAIL ) {
757
- Tcl_Panic ("list creation failed: unable to alloc %" TCL_Z_MODIFIER
758
- "u bytes" ,
759
- LIST_SIZE (objc ));
760
+ Tcl_Panic ("list creation failed: unable to alloc %" TCL_SIZE_MODIFIER
761
+ "d bytes" ,
762
+ LIST_SIZE (objc ));
760
763
}
761
764
return NULL ;
762
765
}
@@ -833,7 +836,7 @@ ListStoreReallocate (ListStore *storePtr, Tcl_Size needed)
833
836
}
834
837
return storePtr ;
835
838
}
836
-
839
+
837
840
/*
838
841
*----------------------------------------------------------------------
839
842
*
@@ -1083,7 +1086,7 @@ Tcl_NewListObj(
1083
1086
1084
1087
TclNewObj (listObj );
1085
1088
1086
- if (objc + 1 <= 1 ) {
1089
+ if (objc <= 0 ) {
1087
1090
return listObj ;
1088
1091
}
1089
1092
@@ -1139,7 +1142,7 @@ Tcl_DbNewListObj(
1139
1142
1140
1143
TclDbNewObj (listObj , file , line );
1141
1144
1142
- if (objc + 1 <= 1 ) {
1145
+ if (objc <= 0 ) {
1143
1146
return listObj ;
1144
1147
}
1145
1148
@@ -1301,7 +1304,7 @@ Tcl_SetListObj(
1301
1304
* not be called with objc == 0!
1302
1305
*/
1303
1306
1304
- if (objc + 1 > 1 ) {
1307
+ if (objc > 0 ) {
1305
1308
ListRep listRep ;
1306
1309
/* TODO - perhaps ask for extra space? */
1307
1310
ListRepInit (objc , objv , LISTREP_PANIC_ON_FAIL , & listRep );
@@ -1904,14 +1907,14 @@ Tcl_ListObjIndex(
1904
1907
{
1905
1908
Tcl_Obj * * elemObjs ;
1906
1909
Tcl_Size numElems ;
1907
- int hasAbstractList = TclObjTypeHasProc (listObj ,indexProc ) != 0 ;
1908
1910
1909
1911
/* Empty string => empty list. Avoid unnecessary shimmering */
1910
1912
if (listObj -> bytes == & tclEmptyString ) {
1911
1913
* objPtrPtr = NULL ;
1912
1914
return TCL_OK ;
1913
1915
}
1914
1916
1917
+ int hasAbstractList = TclObjTypeHasProc (listObj ,indexProc ) != 0 ;
1915
1918
if (hasAbstractList ) {
1916
1919
return TclObjTypeIndex (interp , listObj , index , objPtrPtr );
1917
1920
}
@@ -1920,7 +1923,7 @@ Tcl_ListObjIndex(
1920
1923
!= TCL_OK ) {
1921
1924
return TCL_ERROR ;
1922
1925
}
1923
- if (index < 0 || index >= numElems ) {
1926
+ if (( index < 0 ) || ( index >= numElems ) ) {
1924
1927
* objPtrPtr = NULL ;
1925
1928
} else {
1926
1929
* objPtrPtr = elemObjs [index ];
@@ -2748,17 +2751,16 @@ TclLsetList(
2748
2751
* shimmering; see TIP #22 and #23 for details.
2749
2752
*/
2750
2753
2751
- if (!TclHasInternalRep (indexArgObj , & tclListType ) &&
2752
- TclGetIntForIndexM (NULL , indexArgObj , TCL_SIZE_MAX - 1 , & index )
2753
- == TCL_OK ) {
2754
+ if (!TclHasInternalRep (indexArgObj , & tclListType )
2755
+ && TclGetIntForIndexM (NULL , indexArgObj , TCL_SIZE_MAX - 1 , & index )
2756
+ == TCL_OK ) {
2754
2757
2755
2758
if (TclObjTypeHasProc (listObj , setElementProc )) {
2756
2759
indices = & indexArgObj ;
2757
2760
retValueObj =
2758
2761
TclObjTypeSetElement (interp , listObj , 1 , indices , valueObj );
2759
2762
if (retValueObj ) Tcl_IncrRefCount (retValueObj );
2760
2763
} else {
2761
-
2762
2764
/* indexArgPtr designates a single index. */
2763
2765
/* T:listrep-1.{2.1,12.1,15.1,19.1},2.{2.3,9.3,10.1,13.1,16.1}, 3.{4,5,6}.3 */
2764
2766
retValueObj = TclLsetFlat (interp , listObj , 1 , & indexArgObj , valueObj );
@@ -3139,10 +3141,10 @@ TclListObjSetElement(
3139
3141
elemCount = ListRepLength (& listRep );
3140
3142
3141
3143
/* Ensure that the index is in bounds. */
3142
- if (index >= elemCount ) {
3144
+ if (( index < 0 ) || ( index >= elemCount ) ) {
3143
3145
if (interp != NULL ) {
3144
3146
Tcl_SetObjResult (interp , Tcl_ObjPrintf (
3145
- "index \"%" TCL_Z_MODIFIER "u\" out of range" , index ));
3147
+ "index \"%" TCL_SIZE_MODIFIER "u\" out of range" , index ));
3146
3148
Tcl_SetErrorCode (interp , "TCL" , "VALUE" , "INDEX" ,
3147
3149
"OUTOFRANGE" , NULL );
3148
3150
}
0 commit comments