Tcl Source Code

Check-in [9b1cb4c030]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[824752f10e] More robust, portable check for integer overflow.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-5-branch
Files: files | file ages | folders
SHA1: 9b1cb4c030aaf1e61af547c2d2ac5d6f6b3caa59
User & Date: dgp 2016-11-04 14:37:50
Context
2016-11-11
10:53
Fix [79614fb8b6]: "glob", "encoding system" and encoding-fr... check-in: e0649af0bd user: jan.nijtmans tags: core-8-5-branch
2016-11-04
14:40
[824752f10e] More robust, portable check for integer overflow. check-in: b2a4266498 user: dgp tags: core-8-6-branch
14:37
[824752f10e] More robust, portable check for integer overflow. check-in: 9b1cb4c030 user: dgp tags: core-8-5-branch
14:21
[824752f10e] Avoid calling Tcl_SetObjResult if interp is NULL check-in: b6601d604f user: gahr tags: core-8-5-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclListObj.c.

842
843
844
845
846
847
848

849
850
851
852
853
854
855
856
857
858
859
860
	first = 0;
    }
    if (first >= numElems) {
	first = numElems;	/* So we'll insert after last element. */
    }
    if (count < 0) {
	count = 0;

    } else if (numElems < first+count || first+count < 0) {
	/*
	 * The 'first+count < 0' condition here guards agains integer
	 * overflow in determining 'first+count'
	 */
	count = numElems - first;
    }

    if (objc > LIST_MAX - (numElems - count)) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "max length of a Tcl list (%d elements) exceeded",






>
|
<
<
<
<







842
843
844
845
846
847
848
849
850




851
852
853
854
855
856
857
	first = 0;
    }
    if (first >= numElems) {
	first = numElems;	/* So we'll insert after last element. */
    }
    if (count < 0) {
	count = 0;
    } else if (first > INT_MAX - count /* Handle integer overflow */
	    || numElems < first+count) {




	count = numElems - first;
    }

    if (objc > LIST_MAX - (numElems - count)) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "max length of a Tcl list (%d elements) exceeded",