Skip to content

Commit

Permalink
Updates related to TIP 660
Browse files Browse the repository at this point in the history
  • Loading branch information
apnadkarni committed Apr 21, 2023
2 parents 5406630 + ca3b657 commit c0f6ddc
Show file tree
Hide file tree
Showing 31 changed files with 259 additions and 256 deletions.
6 changes: 3 additions & 3 deletions generic/tkCanvLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,10 @@ LineInsert(
oriNumPoints = linePtr->numPoints;
length = 2*linePtr->numPoints;
nbInsPoints = objc / 2;
if (beforeThis == TCL_INDEX_NONE) {
if (beforeThis < 0) {
beforeThis = 0;
}
if (beforeThis + 1 > (Tcl_Size)length + 1) {
if (beforeThis > length) {
beforeThis = length;
}

Expand Down Expand Up @@ -1876,7 +1876,7 @@ GetLineIndex(
const char *string;

if (TCL_OK == TkGetIntForIndex(obj, 2*linePtr->numPoints - 1, 1, &idx)) {
if (idx == TCL_INDEX_NONE) {
if (idx < 0) {
idx = 0;
} else if (idx > (2*(Tcl_Size)linePtr->numPoints)) {
idx = 2*linePtr->numPoints;
Expand Down
2 changes: 1 addition & 1 deletion generic/tkCanvPoly.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ GetPolygonIndex(
Tcl_Size count = 2*(polyPtr->numPoints - polyPtr->autoClosed);

if (TCL_OK == TkGetIntForIndex(obj, (INT_MAX - 1) - ((INT_MAX) % count), 1, &idx)) {
if (idx == TCL_INDEX_NONE) {
if (idx < 0) {
idx = 0;
} else if (idx >= INT_MAX - ((INT_MAX) % count)) {
idx = count;
Expand Down
60 changes: 30 additions & 30 deletions generic/tkCanvText.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ UnderlineParseProc(
obj.typePtr = NULL;
code = TkGetIntForIndex(&obj, TCL_INDEX_END, 0, &underline);
if (code == TCL_OK) {
if (underline == TCL_INDEX_NONE) {
if (underline < 0) {
underline = (Tcl_Size)INT_MIN;
} else if ((size_t)underline > (size_t)TCL_INDEX_END>>1) {
underline++;
Expand Down Expand Up @@ -431,7 +431,7 @@ TextCoords(
Tcl_ListObjAppendElement(interp, obj, subobj);
Tcl_SetObjResult(interp, obj);
return TCL_OK;
} else if (objc + 1 > 3) {
} else if (objc > 2) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"wrong # coordinates: expected 0 or 2, got %" TKSIZET_MODIFIER "u", objc));
Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "TEXT", NULL);
Expand Down Expand Up @@ -599,19 +599,19 @@ ConfigureText(
textPtr->numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes);
if (textInfoPtr->selItemPtr == itemPtr) {

if (textInfoPtr->selectFirst + 1 >= textPtr->numChars + 1) {
if (textInfoPtr->selectFirst >= textPtr->numChars) {
textInfoPtr->selItemPtr = NULL;
} else {
if (textInfoPtr->selectLast + 1 >= textPtr->numChars + 1) {
if (textInfoPtr->selectLast >= textPtr->numChars) {
textInfoPtr->selectLast = textPtr->numChars - 1;
}
if ((textInfoPtr->anchorItemPtr == itemPtr)
&& (textInfoPtr->selectAnchor + 1 >= textPtr->numChars + 1)) {
&& (textInfoPtr->selectAnchor >= textPtr->numChars)) {
textInfoPtr->selectAnchor = textPtr->numChars - 1;
}
}
}
if (textPtr->insertPos + 1 >= textPtr->numChars + 1) {
if (textPtr->insertPos >= textPtr->numChars) {
textPtr->insertPos = textPtr->numChars;
}

Expand Down Expand Up @@ -924,10 +924,10 @@ DisplayCanvText(
if (textInfoPtr->selItemPtr == itemPtr) {
selFirstChar = textInfoPtr->selectFirst;
selLastChar = textInfoPtr->selectLast;
if (selLastChar + 1 > textPtr->numChars + 1 ) {
if (selLastChar > textPtr->numChars) {
selLastChar = textPtr->numChars - 1;
}
if (((int)selFirstChar >= 0) && (selFirstChar + 1 <= selLastChar + 1 )) {
if ((selFirstChar >= 0) && (selFirstChar <= selLastChar)) {
int xFirst, yFirst, hFirst;
int xLast, yLast, wLast;

Expand Down Expand Up @@ -1102,10 +1102,10 @@ TextInsert(

text = textPtr->text;

if (index == TCL_INDEX_NONE) {
if (index < 0) {
index = 0;
}
if (index + 1 > textPtr->numChars + 1) {
if (index > textPtr->numChars) {
index = textPtr->numChars;
}
byteIndex = Tcl_UtfAtIndex(text, index) - text;
Expand All @@ -1131,18 +1131,18 @@ TextInsert(
*/

if (textInfoPtr->selItemPtr == itemPtr) {
if (textInfoPtr->selectFirst + 1 >= index + 1) {
if (textInfoPtr->selectFirst >= index) {
textInfoPtr->selectFirst += charsAdded;
}
if (textInfoPtr->selectLast + 1 >= index + 1) {
if (textInfoPtr->selectLast >= index) {
textInfoPtr->selectLast += charsAdded;
}
if ((textInfoPtr->anchorItemPtr == itemPtr)
&& (textInfoPtr->selectAnchor + 1 >= index + 1)) {
&& (textInfoPtr->selectAnchor >= index)) {
textInfoPtr->selectAnchor += charsAdded;
}
}
if (textPtr->insertPos + 1 >= index + 1) {
if (textPtr->insertPos >= index) {
textPtr->insertPos += charsAdded;
}
ComputeTextBbox(canvas, textPtr);
Expand Down Expand Up @@ -1180,13 +1180,13 @@ TextDeleteChars(
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;

text = textPtr->text;
if ((int)first < 0) {
if (first < 0) {
first = 0;
}
if (last + 1 >= textPtr->numChars + 1) {
if (last >= textPtr->numChars) {
last = textPtr->numChars - 1;
}
if (first + 1 > last + 1) {
if (first > last) {
return;
}
charsRemoved = last + 1 - first;
Expand All @@ -1210,32 +1210,32 @@ TextDeleteChars(
*/

if (textInfoPtr->selItemPtr == itemPtr) {
if (textInfoPtr->selectFirst + 1 > first + 1) {
if (textInfoPtr->selectFirst > first) {
textInfoPtr->selectFirst -= charsRemoved;
if ((int)textInfoPtr->selectFirst + 1 < (int)first + 1) {
if (textInfoPtr->selectFirst < first) {
textInfoPtr->selectFirst = first;
}
}
if (textInfoPtr->selectLast + 1 >= first + 1) {
if (textInfoPtr->selectLast >= first) {
textInfoPtr->selectLast -= charsRemoved;
if (textInfoPtr->selectLast + 1 < first) {
if (textInfoPtr->selectLast < first - 1) {
textInfoPtr->selectLast = first - 1;
}
}
if ((int)textInfoPtr->selectFirst + 1 > (int)textInfoPtr->selectLast + 1) {
if (textInfoPtr->selectFirst > textInfoPtr->selectLast) {
textInfoPtr->selItemPtr = NULL;
}
if ((textInfoPtr->anchorItemPtr == itemPtr)
&& (textInfoPtr->selectAnchor + 1 > first + 1)) {
&& (textInfoPtr->selectAnchor > first)) {
textInfoPtr->selectAnchor -= charsRemoved;
if (textInfoPtr->selectAnchor + 1 < first + 1) {
if (textInfoPtr->selectAnchor < first) {
textInfoPtr->selectAnchor = first;
}
}
}
if (textPtr->insertPos + 1 > first + 1) {
if (textPtr->insertPos > first) {
textPtr->insertPos -= charsRemoved;
if ((int)textPtr->insertPos + 1 < (int)first + 1) {
if (textPtr->insertPos < first) {
textPtr->insertPos = first;
}
}
Expand Down Expand Up @@ -1468,7 +1468,7 @@ GetTextIndex(
const char *string;

if (TCL_OK == TkGetIntForIndex(obj, textPtr->numChars - 1, 1, &idx)) {
if (idx == TCL_INDEX_NONE) {
if (idx < 0) {
idx = 0;
} else if (idx > textPtr->numChars) {
idx = textPtr->numChars;
Expand Down Expand Up @@ -1563,7 +1563,7 @@ SetTextCursor(
{
TextItem *textPtr = (TextItem *) itemPtr;

if (index == TCL_INDEX_NONE) {
if (index < 0) {
textPtr->insertPos = 0;
} else if (index > textPtr->numChars) {
textPtr->insertPos = textPtr->numChars;
Expand Down Expand Up @@ -1609,8 +1609,8 @@ GetSelText(
const char *selStart, *selEnd;
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;

if (((int)textInfoPtr->selectFirst < 0) ||
(textInfoPtr->selectFirst + 1 > textInfoPtr->selectLast + 1)) {
if ((textInfoPtr->selectFirst < 0) ||
(textInfoPtr->selectFirst > textInfoPtr->selectLast)) {
return 0;
}
text = textPtr->text;
Expand Down
2 changes: 1 addition & 1 deletion generic/tkCanvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -5700,7 +5700,7 @@ CanvasSelectTo(
canvasPtr->textInfo.anchorItemPtr = itemPtr;
canvasPtr->textInfo.selectAnchor = index;
}
if (canvasPtr->textInfo.selectAnchor + 1 <= index + 1) {
if (canvasPtr->textInfo.selectAnchor <= index) {
canvasPtr->textInfo.selectFirst = canvasPtr->textInfo.selectAnchor;
canvasPtr->textInfo.selectLast = index;
} else {
Expand Down
6 changes: 3 additions & 3 deletions generic/tkCmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ ScalingCmd(
double d;

skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);
if (skip == TCL_INDEX_NONE) {
if (skip < 0) {
return TCL_ERROR;
}
screenPtr = Tk_Screen(tkwin);
Expand Down Expand Up @@ -873,7 +873,7 @@ UseinputmethodsCmd(
}

skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);
if (skip == TCL_INDEX_NONE) {
if (skip < 0) {
return TCL_ERROR;
}
dispPtr = ((TkWindow *) tkwin)->dispPtr;
Expand Down Expand Up @@ -934,7 +934,7 @@ InactiveCmd(
Tk_Window tkwin = (Tk_Window)clientData;
Tcl_Size skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);

if (skip == TCL_INDEX_NONE) {
if (skip < 0) {
return TCL_ERROR;
}
if (objc == 1 + skip) {
Expand Down
12 changes: 6 additions & 6 deletions generic/tkConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ DoObjConfig(
}
return TCL_ERROR;
}
if (newIndex == TCL_INDEX_NONE) {
newIndex = (Tcl_Size)INT_MIN;
if (newIndex < 0) {
newIndex = INT_MIN;
} else if ((size_t)newIndex > (size_t)TCL_INDEX_END>>1) {
newIndex++;
}
Expand Down Expand Up @@ -1454,7 +1454,7 @@ Tk_RestoreSavedOptions(
Tk_SavedOptions *savePtr) /* Holds saved option information; must have
* been passed to Tk_SetOptions. */
{
size_t i;
Tcl_Size i;
Option *optionPtr;
Tcl_Obj *newPtr; /* New object value of option, which we
* replace with old value and free. Taken from
Expand All @@ -1474,7 +1474,7 @@ Tk_RestoreSavedOptions(
ckfree(savePtr->nextPtr);
savePtr->nextPtr = NULL;
}
for (i = savePtr->numItems - 1; i != (size_t)-1; i--) {
for (i = savePtr->numItems - 1; i >= 0; i--) {
optionPtr = savePtr->items[i].optionPtr;
specPtr = optionPtr->specPtr;

Expand All @@ -1483,12 +1483,12 @@ Tk_RestoreSavedOptions(
* record.
*/

if (specPtr->objOffset != TCL_INDEX_NONE) {
if (specPtr->objOffset >= 0) {
newPtr = *((Tcl_Obj **) ((char *)savePtr->recordPtr + specPtr->objOffset));
} else {
newPtr = NULL;
}
if (specPtr->internalOffset != TCL_INDEX_NONE) {
if (specPtr->internalOffset >= 0) {
internalPtr = (char *)savePtr->recordPtr + specPtr->internalOffset;
} else {
internalPtr = NULL;
Expand Down
Loading

0 comments on commit c0f6ddc

Please sign in to comment.