summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--generic/tkText.c32
-rw-r--r--generic/tkTextMark.c25
-rw-r--r--tests/textMark.test40
4 files changed, 97 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 75fecd2..3c05f99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2012-01-25 Francois Vogel <fvogelnew1@free.fr>
+ * generic/tkText.c: [Bug-1630271]: segfault/infinite loop
+ * generic/tkTextMark.c: when a mark is before -startline
+ * tests/textMark.test:
+
+2012-01-25 Francois Vogel <fvogelnew1@free.fr>
+
* generic/tkText.c: [Bug-3475627]: Test text-31.11 fails
2012-01-22 Francois Vogel <fvogelnew1@free.fr>
diff --git a/generic/tkText.c b/generic/tkText.c
index 6b42489..76051da 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -2022,6 +2022,7 @@ ConfigureText(
if (mask & TK_TEXT_LINE_RANGE) {
int start, end, current;
+ TkTextIndex index1, index2, index3;
/*
* Line start and/or end have been adjusted. We need to validate the
@@ -2048,13 +2049,15 @@ ConfigureText(
return TCL_ERROR;
}
current = TkBTreeLinesTo(NULL, textPtr->topIndex.linePtr);
+ TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, start, 0,
+ &index1);
+ TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, end, 0,
+ &index2);
if (current < start || current > end) {
TkTextSearch search;
- TkTextIndex index1, first, last;
+ TkTextIndex first, last;
int selChanged = 0;
- TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, start, 0,
- &index1);
TkTextSetYView(textPtr, &index1, 0);
/*
@@ -2098,6 +2101,29 @@ ConfigureText(
textPtr->abortSelections = 1;
}
}
+
+ /* Indices are potentially obsolete after changing -startline and/or
+ * -endline, therefore increase the epoch.
+ * Also, clamp the insert and current (unshared) marks to the new
+ * -startline/-endline range limits of the widget. All other (shared)
+ * marks are unchanged.
+ */
+
+ textPtr->sharedTextPtr->stateEpoch++;
+ TkTextMarkNameToIndex(textPtr, "insert", &index3);
+ if (TkTextIndexCmp(&index3, &index1) < 0) {
+ textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &index1);
+ }
+ if (TkTextIndexCmp(&index3, &index2) > 0) {
+ textPtr->insertMarkPtr = TkTextSetMark(textPtr, "insert", &index2);
+ }
+ TkTextMarkNameToIndex(textPtr, "current", &index3);
+ if (TkTextIndexCmp(&index3, &index1) < 0) {
+ textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &index1);
+ }
+ if (TkTextIndexCmp(&index3, &index2) > 0) {
+ textPtr->currentMarkPtr = TkTextSetMark(textPtr, "current", &index2);
+ }
textPtr->sharedTextPtr->stateEpoch++;
}
diff --git a/generic/tkTextMark.c b/generic/tkTextMark.c
index 55edb46..0e51e33 100644
--- a/generic/tkTextMark.c
+++ b/generic/tkTextMark.c
@@ -402,6 +402,8 @@ TkTextMarkNameToIndex(
TkTextIndex *indexPtr) /* Index information gets stored here. */
{
TkTextSegment *segPtr;
+ TkTextIndex index;
+ int start, end;
if (textPtr == NULL) {
return TCL_ERROR;
@@ -420,6 +422,29 @@ TkTextMarkNameToIndex(
segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);
}
TkTextMarkSegToIndex(textPtr, segPtr, indexPtr);
+
+ /* If indexPtr refers to somewhere outside the -startline/-endline
+ * range limits of the widget, error out since the mark indeed is not
+ * reachable from this text widget (it may be reachable from a peer)
+ * (bug 1630271).
+ */
+
+ if (textPtr->start != NULL) {
+ start = TkBTreeLinesTo(NULL, textPtr->start);
+ TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, start, 0,
+ &index);
+ if (TkTextIndexCmp(indexPtr, &index) < 0) {
+ return TCL_ERROR;
+ }
+ }
+ if (textPtr->end != NULL) {
+ end = TkBTreeLinesTo(NULL, textPtr->end);
+ TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, NULL, end, 0,
+ &index);
+ if (TkTextIndexCmp(indexPtr, &index) > 0) {
+ return TCL_ERROR;
+ }
+ }
return TCL_OK;
}
diff --git a/tests/textMark.test b/tests/textMark.test
index 174f674..c1138ac 100644
--- a/tests/textMark.test
+++ b/tests/textMark.test
@@ -136,6 +136,40 @@ test textMark-6.1 {TkTextMarkSegToIndex} haveCourier12 {
.t mark set d 1.4
list [.t index a] [.t index b] [.t index c ] [.t index d]
} {1.2 1.2 1.2 1.4}
+test textMark-6.2 {TkTextMarkNameToIndex, with mark outside -startline/-endline range - bug 1630271} -body {
+ .t mark set insert 1.0
+ .t configure -startline 2
+ set res [list [.t index insert] [.t index insert-1c] [.t get insert]]
+ .t mark set insert end
+ .t configure -endline 4
+ lappend res [.t index insert]
+} -cleanup {
+ .t configure -startline {} -endline {}
+} -result {1.0 1.0 a 2.5}
+test textMark-6.3 {TkTextMarkNameToIndex, with mark outside -startline/-endline range - bug 1630271} -body {
+ .t mark set mymark 1.0
+ .t configure -startline 2
+ list [catch {.t index mymark} msg] $msg
+} -cleanup {
+ .t configure -startline {} -endline {}
+ .t mark unset mymark
+} -result {1 {bad text index "mymark"}}
+test textMark-6.4 {TkTextMarkNameToIndex, with mark outside -startline/-endline range - bug 1630271} -body {
+ .t mark set mymark 1.0
+ .t configure -startline 2
+ set res [list [catch {.t index mymark} msg] $msg]
+ lappend res [.pt index mymark]
+ .t configure -startline {}
+ .pt configure -startline 4
+ lappend res [.t index mymark]
+ lappend res [catch {.pt index mymark} msg] $msg
+ lappend res [.t get mymark]
+ lappend res [catch {.pt get mymark} msg] $msg
+} -cleanup {
+ .t configure -startline {} -endline {}
+ .pt configure -startline {} -endline {}
+ .t mark unset mymark
+} -result {1 {bad text index "mymark"} 1.0 1.0 1 {bad text index "mymark"} L 1 {bad text index "mymark"}}
catch {eval {.t mark unset} [.t mark names]}
test textMark-7.1 {MarkFindNext - invalid mark name} haveCourier12 {
@@ -180,8 +214,8 @@ test textMark-7.9 {MarkFindNext - mark set in a text widget and retrieved from a
.t mark unset {*}[.t mark names]
} -body {
.t mark set mymark 1.0
- set res [list [.pt mark next 1.0] [.pt mark next mymark] [.pt mark next insert]]
-} -result {mymark insert current}
+ lsort [list [.pt mark next 1.0] [.pt mark next mymark] [.pt mark next insert]]
+} -result {current insert mymark}
test textMark-8.1 {MarkFindPrev - invalid mark name} -constraints haveCourier12 -setup {
.t mark unset {*}[.t mark names]
@@ -242,7 +276,7 @@ test textMark-8.9 {MarkFindPrev - mark set in a text widget and retrieved from a
.t mark unset {*}[.t mark names]
} -body {
.t mark set mymark 1.0
- set res [list [.pt mark prev end] [.pt mark prev current] [.pt mark prev insert]]
+ lsort [list [.pt mark prev end] [.pt mark prev current] [.pt mark prev insert]]
} -result {current insert mymark}
catch {destroy .t}