Re: Seg Fault on NULL strlen



Hi,

Check if "entry2" is defined the first time "on_entry1_changed" is executed.

Maybe the callback is activated when you initialize the value of entry1,
before creating entry2, or something like this.

If it's the case, inserting a test to get out of the callback if entry2 is
NULL, before casting it with GTK_EDITABLE, would solve the seg fault.  If I
understand your code and your explanation, "entry1" shouldn't be NULL at
this point, and should be equal to "editable" because "on_entry1_changed" is
connected to "entry1".

Regards,

Patrice St-Gelais
________________________________

Steve & Patti Getzinger a écrit :

I am attempting to set sensitivity based on entries in 3 entry boxes. So
basically the first is easy. I am hitting a func on changed of entry1 in
the func I am doing an

void
on_entry1_changed                (GtkEditable     *editable,
                                        gpointer         user_data)
{
  if(strlen(gtk_editable_get_chars(GTK_EDITABLE(entry1),0,-1)) > 7)
        {

if(strlen(gtk_editable_get_chars(GTK_EDITABLE(entry2),0,-1)) > 0)

                        {
                        gtk_widget_set_sensitive (button1, TRUE);
                        }
        }else{
                gtk_widget_set_sensitive (button1, FALSE);
        }
}

With this config it seg faults with:

(gdiald:16598): GLib-GObject-WARNING **: invalid cast from (NULL)
pointer to `GtkEditable'

(gdiald:16598): Gtk-CRITICAL **: file gtkeditable.c: line 125
(gtk_editable_get_chars): assertion `GTK_IS_EDITABLE (editable)' failed
Segmentation fault

I am assuming strlen returns NULL if there has been no entry made in
entry2. How do I get around this one?

TIA
Steve

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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