summaryrefslogtreecommitdiffstats
path: root/generic/tkTextBTree.c
diff options
context:
space:
mode:
authorfvogelnew1@free.fr <fvogel>2012-02-28 20:44:34 (GMT)
committerfvogelnew1@free.fr <fvogel>2012-02-28 20:44:34 (GMT)
commitf896a5c5ac2e8ddd9ca9af18c2c32aee666aae77 (patch)
treed62de6938569517afd6274d9096c99eadec78078 /generic/tkTextBTree.c
parentcc982a03fa37479a6630385096025220e145dc59 (diff)
parentb27417f3da0d343314fdc59f063de849b5681f0f (diff)
downloadtk-f896a5c5ac2e8ddd9ca9af18c2c32aee666aae77.zip
tk-f896a5c5ac2e8ddd9ca9af18c2c32aee666aae77.tar.gz
tk-f896a5c5ac2e8ddd9ca9af18c2c32aee666aae77.tar.bz2
[Bug-1630262], [Bug-1615425]: segfault when deleting lines or tagging outside of the -startline/-endline range with peer text widgets. [Bug-3487407]: Weird text indices.
Diffstat (limited to 'generic/tkTextBTree.c')
-rw-r--r--generic/tkTextBTree.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index 572c623..e34dae7 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -658,12 +658,12 @@ AdjustStartEndRefs(
if (textPtr->start != NULL) {
count--;
treePtr->startEnd[count] = textPtr->start;
- treePtr->startEndRef[count] = treePtr->sharedTextPtr->peers;
+ treePtr->startEndRef[count] = textPtr;
}
if (textPtr->end != NULL) {
count--;
treePtr->startEnd[count] = textPtr->end;
- treePtr->startEndRef[count] = treePtr->sharedTextPtr->peers;
+ treePtr->startEndRef[count] = textPtr;
}
}
}
@@ -1606,7 +1606,7 @@ TkBTreeFindLine(
}
/*
- * Check for the any start/end offset for this text widget.
+ * Check for any start/end offset for this text widget.
*/
if (textPtr != NULL) {
@@ -1988,12 +1988,37 @@ TkBTreeLinesTo(
index += nodePtr2->numLines;
}
}
- if (textPtr != NULL && textPtr->start != NULL) {
- index -= TkBTreeLinesTo(NULL, textPtr->start);
+ if (textPtr != NULL) {
+ /*
+ * The index to return must be relative to textPtr, not to the entire
+ * tree. Take care to never return a negative index when linePtr
+ * denotes a line before -startline, or an index larger than the
+ * number of lines in textPtr when linePtr is a line past -endline.
+ */
+
+ int indexStart, indexEnd;
+
+ if (textPtr->start != NULL) {
+ indexStart = TkBTreeLinesTo(NULL, textPtr->start);
+ } else {
+ indexStart = 0;
+ }
+ if (textPtr->end != NULL) {
+ indexEnd = TkBTreeLinesTo(NULL, textPtr->end);
+ } else {
+ indexEnd = TkBTreeNumLines(textPtr->sharedTextPtr->tree, NULL);
+ }
+ if (index < indexStart) {
+ index = 0;
+ } else if (index > indexEnd) {
+ index = TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr);
+ } else {
+ index -= indexStart;
+ }
}
return index;
}
-
+
/*
*----------------------------------------------------------------------
*