diff options
-rw-r--r-- | generic/tclStringObj.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index b1046b1..975b991 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -575,6 +575,9 @@ Tcl_GetUniChar( if (stringPtr->numChars == -1) { TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length); } + if (index >= stringPtr->numChars) { + return 0xFFFD; + } if (stringPtr->numChars == objPtr->length) { return (unsigned char) objPtr->bytes[index]; } @@ -631,7 +634,11 @@ TclGetUCS4( if (stringPtr->numChars == -1) { TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length); } + if (index >= stringPtr->numChars) { + return -1; + } if (stringPtr->numChars == objPtr->length) { + /* Pure ascii, can directly index bytes */ return (unsigned char) objPtr->bytes[index]; } FillUnicodeRep(objPtr); |