diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-01-18 15:39:21 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-01-18 15:39:21 (GMT) |
| commit | f97560a94963b378ccc5b75e5dbc2949eca30b9f (patch) | |
| tree | 9cab1970a2554690061d6b0cb437de08f09ffffa /generic/tclStringObj.c | |
| parent | 01a48e2369782044a30d922c5f8ed52262ef4fcd (diff) | |
| parent | c3bcd951b8dd8bf57202915b9d914bcddc73b9bb (diff) | |
| download | tcl-f97560a94963b378ccc5b75e5dbc2949eca30b9f.zip tcl-f97560a94963b378ccc5b75e5dbc2949eca30b9f.tar.gz tcl-f97560a94963b378ccc5b75e5dbc2949eca30b9f.tar.bz2 | |
Fix [e9a2715d91]: Incompatible Tcl_GetRange(). From now on (unofficially) the last function argument can be set to -1 (or any negative value) meaning 'end'.
Diffstat (limited to 'generic/tclStringObj.c')
| -rw-r--r-- | generic/tclStringObj.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 756b948..b4f05dd 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -772,7 +772,7 @@ Tcl_GetRange( if (TclIsPureByteArray(objPtr)) { unsigned char *bytes = Tcl_GetByteArrayFromObj(objPtr, &length); - if (last >= length) { + if (last < 0 || last >= length) { last = length - 1; } if (last < first) { @@ -798,7 +798,7 @@ Tcl_GetRange( TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length); } if (stringPtr->numChars == objPtr->length) { - if (last >= stringPtr->numChars) { + if (last < 0 || last >= stringPtr->numChars) { last = stringPtr->numChars - 1; } if (last < first) { @@ -819,7 +819,7 @@ Tcl_GetRange( FillUnicodeRep(objPtr); stringPtr = GET_STRING(objPtr); } - if (last >= stringPtr->numChars) { + if (last < 0 || last >= stringPtr->numChars) { last = stringPtr->numChars - 1; } if (last < first) { @@ -2116,7 +2116,11 @@ Tcl_AppendFormatToObj( if (gotPrecision) { numChars = Tcl_GetCharLength(segment); if (precision < numChars) { - segment = Tcl_GetRange(segment, 0, precision - 1); + if (precision < 1) { + TclNewObj(segment); + } else { + segment = Tcl_GetRange(segment, 0, precision - 1); + } numChars = precision; Tcl_IncrRefCount(segment); allocSegment = 1; |
