Tcl Source Code

Check-in [77a7d8d123]
Login

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

Overview
Comment:Fix [0e92c404f1]: Side effect on string range command (from encoding and format commands)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | mistake
Files: files | file ages | folders
SHA1: 77a7d8d12363281e2e0bfeafc848c6a0da087a09
User & Date: jan.nijtmans 2014-04-30 20:22:40
References
2014-04-30
20:38 Closed ticket [0e92c404f1]: Side effect on string range command (from encoding and format commands) plus 7 other changes artifact: 685bd28123 user: jan.nijtmans
Context
2014-04-30
20:22
Fix [0e92c404f1]: Side effect on string range command (from encoding and format commands) Closed-Leaf check-in: 77a7d8d123 user: jan.nijtmans tags: mistake
19:54
Stop the segfaults in [close] during [gets] tests. Not sure this is the right behavior, but it's bet... check-in: 04b1f8b14c user: dgp tags: core-8-5-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclCmdMZ.c.

2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094

2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
static int
StringRangeCmd(
    ClientData dummy,		/* Not used. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    const unsigned char *string;
    int length, first, last;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 1, objv, "string first last");
	return TCL_ERROR;
    }

    /*
     * If we have a ByteArray object, avoid indexing in the Utf string since
     * the byte array contains one byte per character. Otherwise, use the
     * Unicode string rep to get the range.
     */

    if (objv[1]->typePtr == &tclByteArrayType) {
	string = Tcl_GetByteArrayFromObj(objv[1], &length);
	length--;
    } else {
	/*
	 * Get the length in actual characters.

	 */

	string = NULL;
	length = Tcl_GetCharLength(objv[1]) - 1;
    }

    if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK ||
	    TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK) {
	return TCL_ERROR;
    }

    if (first < 0) {
	first = 0;
    }
    if (last >= length) {
	last = length;
    }
    if (last >= first) {
	if (string != NULL) {
	    /*
	     * Reread the string to prevent shimmering nasties.
	     */

	    string = Tcl_GetByteArrayFromObj(objv[1], &length);
	    Tcl_SetObjResult(interp,
		    Tcl_NewByteArrayObj(string+first, last - first + 1));
	} else {
	    Tcl_SetObjResult(interp, Tcl_GetRange(objv[1], first, last));
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *







<








<
<
<
<
<
<
<
<
<
<
|
>
|

<
|
<













<
<
<
<
<
<
<
<
<
|
<







2068
2069
2070
2071
2072
2073
2074

2075
2076
2077
2078
2079
2080
2081
2082










2083
2084
2085
2086

2087

2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100









2101

2102
2103
2104
2105
2106
2107
2108
static int
StringRangeCmd(
    ClientData dummy,		/* Not used. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{

    int length, first, last;

    if (objc != 4) {
	Tcl_WrongNumArgs(interp, 1, objv, "string first last");
	return TCL_ERROR;
    }

    /*










     * Get the length in actual characters; Then reduce it by one because
     * 'end' refers to the last character, not one past it.
     */


    length = Tcl_GetCharLength(objv[1]) - 1;


    if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK ||
	    TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK) {
	return TCL_ERROR;
    }

    if (first < 0) {
	first = 0;
    }
    if (last >= length) {
	last = length;
    }
    if (last >= first) {









	Tcl_SetObjResult(interp, Tcl_GetRange(objv[1], first, last));

    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *