summaryrefslogtreecommitdiffstats
path: root/generic/tkCanvPoly.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-03-18 16:20:07 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-03-18 16:20:07 (GMT)
commit1c9d56a0f8ddd1cdc87789648eb7032671b2607e (patch)
tree5b3b3bd718bbfd7fa5662f158d77f1205b072c5a /generic/tkCanvPoly.c
parentbeb7fb810b843573cb513577c6ed9f7c56c4741e (diff)
downloadtk-1c9d56a0f8ddd1cdc87789648eb7032671b2607e.zip
tk-1c9d56a0f8ddd1cdc87789648eb7032671b2607e.tar.gz
tk-1c9d56a0f8ddd1cdc87789648eb7032671b2607e.tar.bz2
More internal use of TkGetIntForIndex() function.
Diffstat (limited to 'generic/tkCanvPoly.c')
-rw-r--r--generic/tkCanvPoly.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c
index 19c5f6d..1fd71bc 100644
--- a/generic/tkCanvPoly.c
+++ b/generic/tkCanvPoly.c
@@ -1679,16 +1679,25 @@ GetPolygonIndex(
* itemPtr's line. */
int *indexPtr) /* Where to store converted index. */
{
+ TkSizeT length, idx;
PolygonItem *polyPtr = (PolygonItem *) itemPtr;
- const char *string = Tcl_GetString(obj);
+ const char *string;
(void)canvas;
+ TkSizeT count = 2*(polyPtr->numPoints - polyPtr->autoClosed);
- if (string[0] == 'e') {
- if (strncmp(string, "end", obj->length) != 0) {
- goto badIndex;
+ if (TCL_OK == TkGetIntForIndex(obj, (INT_MAX) - ((INT_MAX) % count), &idx)) {
+ if (idx == TCL_INDEX_NONE) {
+ idx = 0;
+ } else {
+ idx = (idx & (TkSizeT)-2) % count;
}
- *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed);
- } else if (string[0] == '@') {
+ *indexPtr = (int)idx;
+ return TCL_OK;
+ }
+
+ string = TkGetStringFromObj(obj, &length);
+
+ if (string[0] == '@') {
int i;
double x, y, bestDist, dist, *coordPtr;
char *end;
@@ -1716,31 +1725,17 @@ GetPolygonIndex(
coordPtr += 2;
}
} else {
- int count = 2*(polyPtr->numPoints - polyPtr->autoClosed);
+ /*
+ * Some of the paths here leave messages in interp->result, so we have to
+ * clear it out before storing our own message.
+ */
- if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) {
- goto badIndex;
- }
- *indexPtr &= -2; /* if odd, make it even */
- if (!count) {
- *indexPtr = 0;
- } else if (*indexPtr > 0) {
- *indexPtr = ((*indexPtr - 2) % count) + 2;
- } else {
- *indexPtr = -((-(*indexPtr)) % count);
- }
+ badIndex:
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
+ Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "POLY", NULL);
+ return TCL_ERROR;
}
return TCL_OK;
-
- /*
- * Some of the paths here leave messages in interp->result, so we have to
- * clear it out before storing our own message.
- */
-
- badIndex:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
- Tcl_SetErrorCode(interp, "TK", "CANVAS", "ITEM_INDEX", "POLY", NULL);
- return TCL_ERROR;
}
/*