summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-18 22:18:06 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-18 22:18:06 (GMT)
commit3dd30ce854309c3433f211cacf5c430b9e8d0005 (patch)
treecea6b362d1fc7f6315ccc14561204ab0e5ef465d /generic/tclUtil.c
parent257a1027899b2e8dc1cfec0d19b966d43d5f9cb2 (diff)
downloadtcl-3dd30ce854309c3433f211cacf5c430b9e8d0005.zip
tcl-3dd30ce854309c3433f211cacf5c430b9e8d0005.tar.gz
tcl-3dd30ce854309c3433f211cacf5c430b9e8d0005.tar.bz2
Clamp output of TclIndexDecode() between -1 (TCL_INDEX_NONE) and INT_MAX. Use this to produce slightly better error-message for lsort -index
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index a2670d5..04fc2af 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -4159,10 +4159,14 @@ TclIndexDecode(
int encoded, /* Value to decode */
int endValue) /* Meaning of "end" to use, > TCL_INDEX_END */
{
- if (encoded <= TCL_INDEX_END) {
- return (encoded - TCL_INDEX_END) + endValue;
+ if (encoded > TCL_INDEX_END) {
+ return encoded;
}
- return encoded;
+ endValue += encoded - TCL_INDEX_END;
+ if (endValue >= 0) {
+ return endValue;
+ }
+ return TCL_INDEX_NONE;
}
/*