diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-05-19 11:00:04 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-05-19 11:00:04 (GMT) |
commit | b4b177bc926f1e246054462ba147e0448a0a95e3 (patch) | |
tree | 683daa1e2e627a09aad80ed74f28dc0e54a00218 /generic/tclObj.c | |
parent | 2e04ff831d043373741c9252f3ff791bbc2bbda9 (diff) | |
download | tcl-b4b177bc926f1e246054462ba147e0448a0a95e3.zip tcl-b4b177bc926f1e246054462ba147e0448a0a95e3.tar.gz tcl-b4b177bc926f1e246054462ba147e0448a0a95e3.tar.bz2 |
Elaborate TIP #481 implementation: Make clear that Tcl_GetUnicodeFromObj and Tcl_GetStringFromObj panic if lengthPtr points to an int and length > INT_MAX.
Also if sizeof(int) == sizeof(size_t), prefer the size_t variant of the functions
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r-- | generic/tclObj.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c index b4d6332..300e408 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -1675,7 +1675,11 @@ TclGetStringFromObj( } } if (lengthPtr != NULL) { - *lengthPtr = (objPtr->length < INT_MAX)? objPtr->length: INT_MAX; + if (objPtr->length > INT_MAX) { + Tcl_Panic("Tcl_GetStringFromObj with 'int' lengthPtr" + "cannot handle such long strings. Please use 'size_t'"); + } + *lengthPtr = (int)objPtr->length; } return objPtr->bytes; } |