Re: Seg Fault on NULL strlen



Steve:

On Sat, 2002-12-28 at 17:38, Steve & Patti Getzinger wrote:
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?


Switch your if statement around.  Drop the strlens, and check for NULL
directly (i.e., strlen=0), and if true, set_sensitive FALSE, otherwise
(i.e., strlen>0), set_sensitive TRUE.

Neil





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