summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdIL.c
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2020-01-17 17:15:37 (GMT)
committersebres <sebres@users.sourceforge.net>2020-01-17 17:15:37 (GMT)
commit668c35bfc263a4e42679779e17e923f019e67f15 (patch)
treec1750985eb9578349e17701747e2752c86860c66 /generic/tclCmdIL.c
parent37ad5db2968eee2ab488b989f8e0a05d53f05408 (diff)
parent33c6ac50b373b13b165fedde951fc841196e5fb8 (diff)
downloadtcl-668c35bfc263a4e42679779e17e923f019e67f15.zip
tcl-668c35bfc263a4e42679779e17e923f019e67f15.tar.gz
tcl-668c35bfc263a4e42679779e17e923f019e67f15.tar.bz2
merge 8.6
Diffstat (limited to 'generic/tclCmdIL.c')
-rw-r--r--generic/tclCmdIL.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 9d4bbf3..854a955 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -3992,9 +3992,11 @@ Tcl_LsortObjCmd(
int sortMode = SORTMODE_ASCII;
int group, groupSize, groupOffset, idx, allocatedIndexVector = 0;
Tcl_Obj *resultPtr, *cmdPtr, **listObjPtrs, *listObj, *indexPtr;
+ size_t elmArrSize;
SortElement *elementArray = NULL, *elementPtr;
SortInfo sortInfo; /* Information about this sort that needs to
* be passed to the comparison function. */
+# define MAXCALLOC 1024000
# define NUM_LISTS 30
SortElement *subList[NUM_LISTS+1];
/* This array holds pointers to temporary
@@ -4317,7 +4319,19 @@ Tcl_LsortObjCmd(
* begins sorting it into the sublists as it appears.
*/
- elementArray = ckalloc(length * sizeof(SortElement));
+ elmArrSize = length * sizeof(SortElement);
+ if (elmArrSize <= MAXCALLOC) {
+ elementArray = ckalloc(elmArrSize);
+ } else {
+ elementArray = malloc(elmArrSize);
+ }
+ if (!elementArray) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "no enough memory to proccess sort of %d items", length));
+ Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
+ sortInfo.resultCode = TCL_ERROR;
+ goto done;
+ }
for (i=0; i < length; i++) {
idx = groupSize * i + groupOffset;
@@ -4450,7 +4464,11 @@ Tcl_LsortObjCmd(
TclStackFree(interp, sortInfo.indexv);
}
if (elementArray) {
- ckfree(elementArray);
+ if (elmArrSize <= MAXCALLOC) {
+ ckfree((char *)elementArray);
+ } else {
+ free((char *)elementArray);
+ }
}
return sortInfo.resultCode;
}