From 84d93a6e998f4394ae62cec0ea81fa96287a8d7a Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 17 Mar 2020 21:51:19 +0000 Subject: Follow-up to [d9bda1d1]: Clamp "listbox index" values between -1 and (maximum) end+1 = the number of elements, which point to one more than the last emlement.... that's what other GUI elements are really doing too. Duh. --- generic/tkListbox.c | 2 +- tests/listbox.test | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index c121acb..d456a13 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -2799,7 +2799,7 @@ GetListboxIndex( if (*indexPtr < -1) { *indexPtr = -1; } else if (*indexPtr > listPtr->nElements) { - *indexPtr = listPtr->nElements + (endIsSize ? 1 : 0); + *indexPtr = listPtr->nElements; } return TCL_OK; } diff --git a/tests/listbox.test b/tests/listbox.test index f994e45..98ec96c 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -724,7 +724,7 @@ test listbox-3.62 {ListboxWidgetCmd procedure, "index" option} -body { } -result 18 test listbox-3.63 {ListboxWidgetCmd procedure, "index" option} -body { .l index 34 -} -result 19 +} -result 18 test listbox-3.64 {ListboxWidgetCmd procedure, "insert" option} -body { .l insert } -returnCodes error -result {wrong # args: should be ".l insert index ?element ...?"} @@ -2112,7 +2112,7 @@ test listbox-10.17 {GetListboxIndex procedure} -setup { .l index 20 } -cleanup { destroy .l -} -result {13} +} -result {12} test listbox-10.18 {GetListboxIndex procedure} -setup { destroy .l } -body { @@ -2143,7 +2143,7 @@ test listbox-10.20 {GetListboxIndex procedure} -setup { .l index 1 } -cleanup { destroy .l -} -result 1 +} -result 0 test listbox-11.1 {ChangeListboxView procedure, boundary conditions for index} -setup { -- cgit v0.12