Code changes from commit f40daf97c2c369dce9572b93feaf896ceb47a30c
Author: Morten Welinder <terra@gnome.org>
Date:   Thu Nov 4 16:42:06 2010 -0400

    GUI: Fix gtk+/X crash with large tooltips relating to fill-by-drag.

diff --git a/src/item-cursor.c b/src/item-cursor.c
index b0673ae..6d10a9a 100644
--- a/src/item-cursor.c
+++ b/src/item-cursor.c
@@ -911,6 +911,33 @@ item_cursor_drag_motion (ItemCursor *ic, double x, double y)
 	return TRUE;
 }
 
+static void
+limit_string_height_and_width (GString *s, size_t wmax, size_t hmax)
+{
+	size_t l;
+	size_t p = 0;
+	for (l = 0; l < hmax; l++) {
+		size_t ll = 0;
+		size_t cut = 0;
+		while (s->str[p] != 0 && s->str[p] != '\n') {
+			if (ll == wmax)
+				cut = p;
+			ll++;
+			p += g_utf8_skip[(unsigned char)(s->str[p])];
+		}
+
+		if (cut) {
+			g_string_erase (s, cut, p - cut);
+			p = cut;
+		}
+		if (s->str[p] == 0)
+			return;
+		p++;
+	}
+	g_string_truncate (s, p);
+}
+
+
 static gboolean
 cb_autofill_scroll (GnmPane *pane, GnmPaneSlideInfo const *info)
 {
@@ -968,7 +995,7 @@ cb_autofill_scroll (GnmPane *pane, GnmPaneSlideInfo const *info)
 		gboolean default_increment =
 			ic->drag_button_state & GDK_CONTROL_MASK;
 		Sheet *sheet = scg_sheet (ic->scg);
-		char *hint;
+		GString *hint;
 
 		if (inverse_autofill)
 			hint = gnm_autofill_hint
@@ -984,8 +1011,9 @@ cb_autofill_scroll (GnmPane *pane, GnmPaneSlideInfo const *info)
 				 ic->pos.end.col, ic->pos.end.row);
 
 		if (hint) {
-			item_cursor_tip_setlabel (ic, hint);
-			g_free (hint);
+			limit_string_height_and_width (hint, 200, 200);
+			item_cursor_tip_setlabel (ic, hint->str);
+			g_string_free (hint, TRUE);
 		} else
 			item_cursor_tip_setlabel (ic, "");
 	}
diff --git a/src/sheet-autofill.c b/src/sheet-autofill.c
index aa17a7f..af89b23 100644
--- a/src/sheet-autofill.c
+++ b/src/sheet-autofill.c
@@ -1200,7 +1200,7 @@ add_item (GString *dst, char *item, char const *sep)
 		g_string_append (dst, "?");
 }
 
-static char *
+static GString *
 sheet_autofill_internal (Sheet *sheet, gboolean singleton,
 			 int base_col, int base_row,
 			 int w, int h,
@@ -1291,7 +1291,7 @@ sheet_autofill_internal (Sheet *sheet, gboolean singleton,
 		}
 	}
 
-	return doit ? NULL : g_string_free (res, FALSE);
+	return res;
 }
 
 
@@ -1315,7 +1315,7 @@ gnm_autofill_fill (Sheet *sheet, gboolean singleton,
 				 TRUE);
 }
 
-char *
+GString *
 gnm_autofill_hint (Sheet *sheet, gboolean default_increment,
 		   int base_col, int base_row,
 		   int w,        int h,
diff --git a/src/sheet-autofill.h b/src/sheet-autofill.h
index 88f4d32..8ba2f91 100644
--- a/src/sheet-autofill.h
+++ b/src/sheet-autofill.h
@@ -14,10 +14,10 @@ void gnm_autofill_fill (Sheet *sheet, gboolean default_increment,
 			int w,        int h,
 			int end_col,  int end_row);
 
-char *gnm_autofill_hint (Sheet *sheet, gboolean default_increment,
-			 int base_col, int base_row,
-			 int w,        int h,
-			 int end_col,  int end_row);
+GString *gnm_autofill_hint (Sheet *sheet, gboolean default_increment,
+			    int base_col, int base_row,
+			    int w,        int h,
+			    int end_col,  int end_row);
 
 G_END_DECLS
 
