pidgin: 5a6e3558: Make sure the selection is within bounds...

sadrul at pidgin.im sadrul at pidgin.im
Tue Oct 27 20:35:43 EDT 2009


-----------------------------------------------------------------
Revision: 5a6e3558c6661c5485cae1b1c8d3add3fae9da6b
Ancestor: 371c4bb92e5001e2cd97c9c26336cc9666e9bef3
Author: sadrul at pidgin.im
Date: 2009-10-27T23:37:52
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5a6e3558c6661c5485cae1b1c8d3add3fae9da6b

Modified files:
        finch/libgnt/gnttextview.c

ChangeLog: 

Make sure the selection is within bounds before accepting a click-drag
selection in a textview.

-------------- next part --------------
============================================================
--- finch/libgnt/gnttextview.c	f89e1690097873356a26699a17dc12496dbc69b0
+++ finch/libgnt/gnttextview.c	a5621d9b3331ebb9c5dec9d863b239549db19a31
@@ -67,6 +67,12 @@ static void reset_text_view(GntTextView 
 
 static void reset_text_view(GntTextView *view);
 
+static gboolean
+text_view_contains(GntTextView *view, const char *str)
+{
+	return (str >= view->string->str && str < view->string->str + view->string->len);
+}
+
 static void
 gnt_text_view_draw(GntWidget *widget)
 {
@@ -109,7 +115,7 @@ gnt_text_view_draw(GntWidget *widget)
 			char back = *end;
 			chtype fl = seg->flags;
 			*end = '\0';
-			if (select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) {
+			if (select_start && select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) {
 				fl |= A_REVERSE;
 				wattrset(widget->window, fl);
 				wprintw(widget->window, "%s", (view->string->str + seg->start));
@@ -326,9 +332,10 @@ gnt_text_view_clicked(GntWidget *widget,
 		select_start = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y);
 		g_timeout_add(500, too_slow, NULL);
 	} else if (event == GNT_MOUSE_UP) {
-		if (select_start) {
+		GntTextView *view = GNT_TEXT_VIEW(widget);
+		if (text_view_contains(view, select_start)) {
 			GString *clip;
-			select_end = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y);
+			select_end = gnt_text_view_get_p(view, x - widget->priv.x, y - widget->priv.y);
 			if (select_end < select_start) {
 				gchar *t = select_start;
 				select_start = select_end;
@@ -336,7 +343,7 @@ gnt_text_view_clicked(GntWidget *widget,
 			}
 			if (select_start == select_end) {
 				if (double_click) {
-					clip = select_word_text(GNT_TEXT_VIEW(widget), select_start);
+					clip = select_word_text(view, select_start);
 					double_click = FALSE;
 				} else {
 					double_click = TRUE;


More information about the Commits mailing list