Skip to content

Commit ffee5d0

Browse files
author
jan.nijtmans
committed
Merge 8.7
2 parents 6bcf9e5 + 55d0859 commit ffee5d0

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

generic/tclListObj.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
/*
119119
* Prototypes for non-inline static functions defined later in this file:
120120
*/
121-
static int MemoryAllocationError(Tcl_Interp *, Tcl_Size size);
121+
static int MemoryAllocationError(Tcl_Interp *, size_t size);
122122
static int ListLimitExceededError(Tcl_Interp *);
123123
static ListStore *ListStoreNew(Tcl_Size objc, Tcl_Obj *const objv[], int flags);
124124
static int ListRepInit(Tcl_Size objc, Tcl_Obj *const objv[], int flags, ListRep *);
@@ -463,15 +463,15 @@ ObjArrayCopy(
463463
static int
464464
MemoryAllocationError(
465465
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 */
467467
{
468468
if (interp != NULL) {
469469
Tcl_SetObjResult(
470470
interp,
471471
Tcl_ObjPrintf(
472-
"list construction failed: unable to alloc %" TCL_LL_MODIFIER
472+
"list construction failed: unable to alloc %" TCL_Z_MODIFIER
473473
"u bytes",
474-
(Tcl_WideInt)size));
474+
size));
475475
Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
476476
}
477477
return TCL_ERROR;
@@ -642,8 +642,11 @@ ListRepValidate(const ListRep *repPtr, const char *file, int lineNum)
642642

643643
/* Separate each condition so line number gives exact reason for failure */
644644
INVARIANT(storePtr != NULL);
645+
INVARIANT(storePtr->numAllocated >= 0);
645646
INVARIANT(storePtr->numAllocated <= LIST_MAX);
647+
INVARIANT(storePtr->firstUsed >= 0);
646648
INVARIANT(storePtr->firstUsed < storePtr->numAllocated);
649+
INVARIANT(storePtr->numUsed >= 0);
647650
INVARIANT(storePtr->numUsed <= storePtr->numAllocated);
648651
INVARIANT(storePtr->firstUsed <= (storePtr->numAllocated - storePtr->numUsed));
649652

@@ -754,9 +757,9 @@ ListStoreNew(
754757
}
755758
if (storePtr == NULL) {
756759
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));
760763
}
761764
return NULL;
762765
}
@@ -833,7 +836,7 @@ ListStoreReallocate (ListStore *storePtr, Tcl_Size needed)
833836
}
834837
return storePtr;
835838
}
836-
839+
837840
/*
838841
*----------------------------------------------------------------------
839842
*
@@ -1083,7 +1086,7 @@ Tcl_NewListObj(
10831086

10841087
TclNewObj(listObj);
10851088

1086-
if (objc + 1 <= 1) {
1089+
if (objc <= 0) {
10871090
return listObj;
10881091
}
10891092

@@ -1139,7 +1142,7 @@ Tcl_DbNewListObj(
11391142

11401143
TclDbNewObj(listObj, file, line);
11411144

1142-
if (objc + 1 <= 1) {
1145+
if (objc <= 0) {
11431146
return listObj;
11441147
}
11451148

@@ -1301,7 +1304,7 @@ Tcl_SetListObj(
13011304
* not be called with objc == 0!
13021305
*/
13031306

1304-
if (objc + 1 > 1) {
1307+
if (objc > 0) {
13051308
ListRep listRep;
13061309
/* TODO - perhaps ask for extra space? */
13071310
ListRepInit(objc, objv, LISTREP_PANIC_ON_FAIL, &listRep);
@@ -1904,14 +1907,14 @@ Tcl_ListObjIndex(
19041907
{
19051908
Tcl_Obj **elemObjs;
19061909
Tcl_Size numElems;
1907-
int hasAbstractList = TclObjTypeHasProc(listObj,indexProc) != 0;
19081910

19091911
/* Empty string => empty list. Avoid unnecessary shimmering */
19101912
if (listObj->bytes == &tclEmptyString) {
19111913
*objPtrPtr = NULL;
19121914
return TCL_OK;
19131915
}
19141916

1917+
int hasAbstractList = TclObjTypeHasProc(listObj,indexProc) != 0;
19151918
if (hasAbstractList) {
19161919
return TclObjTypeIndex(interp, listObj, index, objPtrPtr);
19171920
}
@@ -1920,7 +1923,7 @@ Tcl_ListObjIndex(
19201923
!= TCL_OK) {
19211924
return TCL_ERROR;
19221925
}
1923-
if (index < 0 || index >= numElems) {
1926+
if ((index < 0) || (index >= numElems)) {
19241927
*objPtrPtr = NULL;
19251928
} else {
19261929
*objPtrPtr = elemObjs[index];
@@ -2748,17 +2751,16 @@ TclLsetList(
27482751
* shimmering; see TIP #22 and #23 for details.
27492752
*/
27502753

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) {
27542757

27552758
if (TclObjTypeHasProc(listObj, setElementProc)) {
27562759
indices = &indexArgObj;
27572760
retValueObj =
27582761
TclObjTypeSetElement(interp, listObj, 1, indices, valueObj);
27592762
if (retValueObj) Tcl_IncrRefCount(retValueObj);
27602763
} else {
2761-
27622764
/* indexArgPtr designates a single index. */
27632765
/* 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 */
27642766
retValueObj = TclLsetFlat(interp, listObj, 1, &indexArgObj, valueObj);
@@ -3139,10 +3141,10 @@ TclListObjSetElement(
31393141
elemCount = ListRepLength(&listRep);
31403142

31413143
/* Ensure that the index is in bounds. */
3142-
if (index>=elemCount) {
3144+
if ((index < 0) || (index >= elemCount)) {
31433145
if (interp != NULL) {
31443146
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));
31463148
Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX",
31473149
"OUTOFRANGE", NULL);
31483150
}

0 commit comments

Comments
 (0)