Tcl Source Code

Check-in [5bd1e43691]
Login

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

Overview
Comment:[268b23df11] When GetSrcInfoForPc() returns NULL, make sure it also sets the length to a non-positive value so nothing tries to read offsets from a NULL pointer.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5bd1e43691b42586290a5e37e84eeabfaa600eb8
User & Date: dgp 2015-06-03 12:26:38
Context
2015-06-03
17:40
Put the ellipsis inside, not outside, the close quote. check-in: 4ff271315a user: dgp tags: trunk
12:26
[268b23df11] When GetSrcInfoForPc() returns NULL, make sure it also sets the length to a non-positiv... check-in: 5bd1e43691 user: dgp tags: trunk
2015-05-27
18:35
Make tweak to the mem-debug tracking official. It is now again possible to use regular packages with... check-in: ef02e1dfd9 user: andreask tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclExecute.c.

9991
9992
9993
9994
9995
9996
9997

9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
    unsigned char *srcDeltaNext, *srcLengthNext;
    int codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i;
    int bestDist = INT_MAX;	/* Distance of pc to best cmd's start pc. */
    int bestSrcOffset = -1;	/* Initialized to avoid compiler warning. */
    int bestSrcLength = -1;	/* Initialized to avoid compiler warning. */
    int bestCmdIdx = -1;


    if ((pcOffset < 0) || (pcOffset >= codePtr->numCodeBytes)) {
	if (pcBeg != NULL) *pcBeg = NULL;
	return NULL;
    }

    /*
     * Decode the code and source offset and length for each command. The
     * closest enclosing command is the last one whose code started before
     * pcOffset.
     */








>
|
<
<
<







9991
9992
9993
9994
9995
9996
9997
9998
9999



10000
10001
10002
10003
10004
10005
10006
    unsigned char *srcDeltaNext, *srcLengthNext;
    int codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i;
    int bestDist = INT_MAX;	/* Distance of pc to best cmd's start pc. */
    int bestSrcOffset = -1;	/* Initialized to avoid compiler warning. */
    int bestSrcLength = -1;	/* Initialized to avoid compiler warning. */
    int bestCmdIdx = -1;

    /* The pc must point within the bytecode */
    assert ((pcOffset >= 0) && (pcOffset < codePtr->numCodeBytes));




    /*
     * Decode the code and source offset and length for each command. The
     * closest enclosing command is the last one whose code started before
     * pcOffset.
     */

10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096




10097
10098
10099
10100
10101
10102
10103
	while (curr <= pc) {
	    prev = curr;
	    curr += tclInstructionTable[*curr].numBytes;
	}
	*pcBeg = prev;
    }

    if (bestDist == INT_MAX) {
	return NULL;
    }

    if (lengthPtr != NULL) {
	*lengthPtr = bestSrcLength;
    }

    if (cmdIdxPtr != NULL) {
	*cmdIdxPtr = bestCmdIdx;
    }





    return (codePtr->source + bestSrcOffset);
}

/*
 *----------------------------------------------------------------------
 *







<
<
<
<







>
>
>
>







10077
10078
10079
10080
10081
10082
10083




10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
	while (curr <= pc) {
	    prev = curr;
	    curr += tclInstructionTable[*curr].numBytes;
	}
	*pcBeg = prev;
    }





    if (lengthPtr != NULL) {
	*lengthPtr = bestSrcLength;
    }

    if (cmdIdxPtr != NULL) {
	*cmdIdxPtr = bestCmdIdx;
    }

    if (bestDist == INT_MAX) {
	return NULL;
    }

    return (codePtr->source + bestSrcOffset);
}

/*
 *----------------------------------------------------------------------
 *

Changes to tests/execute.test.

1039
1040
1041
1042
1043
1044
1045














1046
1047
1048
1049
1050
1051
1052
	}
	# Crashes on failure
	return ok
    }
} -cleanup {
    interp delete slave
} -result ok















# cleanup
if {[info commands testobj] != {}} {
   testobj freeallvars
}
catch {namespace delete {*}[namespace children :: test_ns_*]}
catch {rename foo ""}







>
>
>
>
>
>
>
>
>
>
>
>
>
>







1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
	}
	# Crashes on failure
	return ok
    }
} -cleanup {
    interp delete slave
} -result ok

test execute-11.2 {Bug 268b23df11} -setup {
    proc zero {} {return 0}
    proc crash {} {expr {abs([zero])}}
    proc noop args {}
    trace add execution crash enterstep noop
} -body {
    crash
} -cleanup {
    trace remove execution crash enterstep noop
    rename noop {}
    rename crash {}
    rename zero {}
} -result 0

# cleanup
if {[info commands testobj] != {}} {
   testobj freeallvars
}
catch {namespace delete {*}[namespace children :: test_ns_*]}
catch {rename foo ""}