summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--generic/tkTextBTree.c10
-rw-r--r--generic/tkTextDisp.c16
-rw-r--r--tests/text.test20
4 files changed, 46 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 489682b..8ff3d56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2004-01-07 Vince Darley <vincentdarley@users.sourceforge.net>
+ * generic/tkTextDisp.c:
+ * generic/tkTextBTree.c:
+ * tests/text.test: fixed crashing [Bug 872299] in yview code,
+ and added tests and better error checking in the B-tree.
+
+2004-01-07 Vince Darley <vincentdarley@users.sourceforge.net>
+
* generic/tkTextIndex.c:
* tests/textIndex.test: fixed bug in which 'wordstart' and
'wordend' were not utf-8 aware (they haven't been changed since
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index b2db5aa..8ac05ea 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkTextBTree.c,v 1.11 2003/12/15 11:51:06 vincentdarley Exp $
+ * RCS: @(#) $Id: tkTextBTree.c,v 1.12 2004/01/07 16:28:23 vincentdarley Exp $
*/
#include "tkInt.h"
@@ -1002,6 +1002,10 @@ TkBTreeFindPixelLine(tree, pixels, pixelOffset)
return NULL;
}
+ if (nodePtr->numPixels == 0) {
+ panic("TkBTreeFindPixelLine called with empty window");
+ }
+
/*
* Work down through levels of the tree until a node is found at
* level 0.
@@ -1012,7 +1016,7 @@ TkBTreeFindPixelLine(tree, pixels, pixelOffset)
nodePtr->numPixels <= pixelsLeft;
nodePtr = nodePtr->nextPtr) {
if (nodePtr == NULL) {
- panic("TkBTreeFindLine ran out of nodes");
+ panic("TkBTreeFindPixelLine ran out of nodes");
}
pixelsLeft -= nodePtr->numPixels;
}
@@ -1026,7 +1030,7 @@ TkBTreeFindPixelLine(tree, pixels, pixelOffset)
linePtr->pixelHeight < pixelsLeft;
linePtr = linePtr->nextPtr) {
if (linePtr == NULL) {
- panic("TkBTreeFindLine ran out of lines");
+ panic("TkBTreeFindPixelLine ran out of lines");
}
pixelsLeft -= linePtr->pixelHeight;
}
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 1fbf4cf..9cab7f8 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkTextDisp.c,v 1.38 2003/12/15 11:51:06 vincentdarley Exp $
+ * RCS: @(#) $Id: tkTextDisp.c,v 1.39 2004/01/07 16:28:23 vincentdarley Exp $
*/
#include "tkPort.h"
@@ -5193,14 +5193,23 @@ TkTextYviewCmd(textPtr, interp, objc, objv)
switch (type) {
case TKTEXT_SCROLL_ERROR:
return TCL_ERROR;
- case TKTEXT_SCROLL_MOVETO:
+ case TKTEXT_SCROLL_MOVETO: {
+ int numPixels = TkBTreeNumPixels(textPtr->tree);
+ if (numPixels == 0) {
+ /*
+ * If the window is totally empty no scrolling is
+ * needed, and the TkTextMakePixelIndex call
+ * below will fail.
+ */
+ break;
+ }
if (fraction > 1.0) {
fraction = 1.0;
}
if (fraction < 0) {
fraction = 0;
}
- fraction *= (TkBTreeNumPixels(textPtr->tree)-1);
+ fraction *= (numPixels - 1);
/*
* This function returns the number of pixels by which the
* given line should overlap the top of the visible screen.
@@ -5211,6 +5220,7 @@ TkTextYviewCmd(textPtr, interp, objc, objv)
(int) (0.5 + fraction), &index);
TkTextSetYView(textPtr, &index, pixels);
break;
+ }
case TKTEXT_SCROLL_PAGES: {
/*
* Scroll up or down by screenfuls. Actually, use the
diff --git a/tests/text.test b/tests/text.test
index bf7314b..1672138 100644
--- a/tests/text.test
+++ b/tests/text.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: text.test,v 1.27 2003/12/05 17:19:06 vincentdarley Exp $
+# RCS: @(#) $Id: text.test,v 1.28 2004/01/07 16:28:45 vincentdarley Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -2929,6 +2929,24 @@ test text-27.4 {tabs - must be positive and must be increasing} {
set result 1
} {1}
+test text-28.0 {repeated insert and scroll} {
+ foreach subcmd {
+ {moveto 1}
+ {scroll 1 pages}
+ {scroll 100 pixels}
+ {scroll 10 units}
+ } {
+ destroy .t
+ pack [text .t]
+ for {set i 0} {$i < 30} {incr i} {
+ .t insert end "blabla\n"
+ eval .t yview $subcmd
+ }
+ }
+ # This test must simply not crash to succeed
+ set result 1
+} {1}
+
deleteWindows
option clear