Yet Another GtkText Bug...

Here's another program that crashes the text widget...I don't know if
it's related to the other bugs...

Run the program, typein "foobar" (or something else with more than 3
lettes), and then press F1.

It'll then crash with:

** ERROR **: file gtktext.c: line 4183 (find_line_params): ""

===File ~/tmp/foo.c=========================================
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

static void
argh (GtkWidget *text)
  static GdkColormap *cmap = NULL;
  GdkColor red;
  gchar *tmp;
  guint pos;

  if (!cmap) {
    cmap = gtk_widget_get_colormap (text); = 65535; = 0; = 0;
    gdk_color_alloc (cmap, &red);

  /* save position */
  pos = gtk_editable_get_position (GTK_EDITABLE (text));

  /* stuff to make it crash */
  tmp = gtk_editable_get_chars (GTK_EDITABLE (text), 0, 3);
  gtk_editable_delete_text (GTK_EDITABLE (text), 0, 3);
  gtk_text_set_point (GTK_TEXT (text), 0);
  gtk_text_insert (GTK_TEXT (text), NULL, &red, NULL,
		   tmp, 3);
  g_free (tmp);

  /* restore position */
  gtk_editable_set_position (GTK_EDITABLE (text), pos);

static gboolean
keypress (GtkWidget *text, GdkEventKey *ev)
  g_return_val_if_fail (text != NULL, FALSE);
  g_return_val_if_fail (ev != NULL, FALSE);

  switch (ev->keyval) {
  case GDK_F1:
    argh (text);

  return FALSE;

main (int argc, char *argv[])
  GtkWidget *window;
  GtkWidget *text;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  text = gtk_text_new (NULL, NULL);
  gtk_text_set_editable (GTK_TEXT (text), TRUE);
  gtk_signal_connect (GTK_OBJECT (text), "key-press-event",
		      GTK_SIGNAL_FUNC (keypress), NULL);
  gtk_container_add (GTK_CONTAINER (window), text);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]