From 7ee90e287a0a8d613e7b76474f9500bb2ac1eed8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 28 Jan 2021 08:01:35 +0000 Subject: Fix for [237971ce]: [$canvas insert] changed behaviour. Also added testcase from Emiliano Gavilan. --- generic/tkCanvLine.c | 2 +- generic/tkCanvPoly.c | 2 ++ tests/canvas.test | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/generic/tkCanvLine.c b/generic/tkCanvLine.c index e7e8904..07dbb70 100644 --- a/generic/tkCanvLine.c +++ b/generic/tkCanvLine.c @@ -1748,7 +1748,7 @@ GetLineIndex( const char *string; (void)canvas; - if (TCL_OK == TkGetIntForIndex(obj, 2*linePtr->numPoints - 1, 0, &idx)) { + if (TCL_OK == TkGetIntForIndex(obj, 2*linePtr->numPoints - 1, 1, &idx)) { if (idx == TCL_INDEX_NONE) { idx = 0; } else if (idx > (2*(TkSizeT)linePtr->numPoints)) { diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c index 1620914..90b2896 100644 --- a/generic/tkCanvPoly.c +++ b/generic/tkCanvPoly.c @@ -1683,6 +1683,8 @@ GetPolygonIndex( if (TCL_OK == TkGetIntForIndex(obj, (INT_MAX - 1) - ((INT_MAX) % count), 1, &idx)) { if (idx == TCL_INDEX_NONE) { idx = 0; + } else if (idx >= INT_MAX - ((INT_MAX) % count)) { + idx = count; } else { idx = (idx & (TkSizeT)-2) % count; } diff --git a/tests/canvas.test b/tests/canvas.test index 5e4f851..ea71193 100644 --- a/tests/canvas.test +++ b/tests/canvas.test @@ -758,6 +758,22 @@ test canvas-15.19 "basic coords check: centimeters are larger than pixels" -setu set id [.c create rect 0 0 1cm 1cm] expr {[lindex [.c coords $id] 2]>1} } -result 1 +test canvas-15.20 {bug [237971ce]} -setup { + destroy .c + canvas .c +} -body { + set id [.c create line {0 0 50 50 100 50}] + .c insert $id end {200 200} + .c coords $id +} -result {0.0 0.0 50.0 50.0 100.0 50.0 200.0 200.0} +test canvas-15.21 {bug [237971ce]} -setup { + destroy .c + canvas .c +} -body { + set id [.c create poly {0 0 50 50 100 50}] + .c insert $id end {200 200} + .c coords $id +} -result {0.0 0.0 50.0 50.0 100.0 50.0 200.0 200.0} destroy .c test canvas-16.1 {arc coords check} -setup { -- cgit v0.12