summaryrefslogtreecommitdiffstats
path: root/generic/tkTextBTree.c
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2012-02-02 10:40:12 (GMT)
committerfvogel <fvogelnew1@free.fr>2012-02-02 10:40:12 (GMT)
commitf376d1c99841e1edea5440aa66932d03e9b0e038 (patch)
treec3591eb7b3dc09fe1d15a0764a5a18cd0a174b10 /generic/tkTextBTree.c
parent7664c99658c07b63bcdfc3827dd74d8da19ef1fd (diff)
downloadtk-f376d1c99841e1edea5440aa66932d03e9b0e038.zip
tk-f376d1c99841e1edea5440aa66932d03e9b0e038.tar.gz
tk-f376d1c99841e1edea5440aa66932d03e9b0e038.tar.bz2
Better fix for bug-1630262, also fixing bug-1615425
Diffstat (limited to 'generic/tkTextBTree.c')
-rw-r--r--generic/tkTextBTree.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index 005ce46..67ff79d 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -1991,17 +1991,37 @@ TkBTreeLinesTo(
index += nodePtr2->numLines;
}
}
- if (textPtr != NULL && textPtr->start != NULL) {
- index -= TkBTreeLinesTo(NULL, textPtr->start);
- if (index < 0) {
- /* One should panic here!
- Tcl_Panic("TkBTreeLinesTo: linePtr comes before -startline");
- */
+ 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;
}
-
+
/*
*----------------------------------------------------------------------
*