diff options
author | fvogel <fvogelnew1@free.fr> | 2012-02-28 20:14:21 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2012-02-28 20:14:21 (GMT) |
commit | 220b6aecbb178564d3ee630cf19c6aa8ae93a67d (patch) | |
tree | add824c5019c64a12957fa0d0b75cc242296b5f7 /generic/tkTextBTree.c | |
parent | 45e67a168fc74dc40011588fc29a08e46d5e8bd6 (diff) | |
parent | 1487608db176d526e0c03938073340f5f2a068eb (diff) | |
download | tk-220b6aecbb178564d3ee630cf19c6aa8ae93a67d.zip tk-220b6aecbb178564d3ee630cf19c6aa8ae93a67d.tar.gz tk-220b6aecbb178564d3ee630cf19c6aa8ae93a67d.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.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c index 0038e64..67ff79d 100644 --- a/generic/tkTextBTree.c +++ b/generic/tkTextBTree.c @@ -662,12 +662,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; } } } @@ -1609,7 +1609,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) { @@ -1991,12 +1991,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; } - + /* *---------------------------------------------------------------------- * |