Re: Seg Fault on NULL strlen



I recently added:

if(gtk_editable_get_chars(GTK_EDITABLE(entry2),0,1) !='\0')

gtk_editable_get_chars returns a character pointer.  This is NOT the
same as an ascii 'nil' character ('\0').  You want to compare
        gtk_editable_get_chars(...) != NULL.

Although your code will work, it confuses 'nil' (a single byte), and
NULL (a pointer value guarented to be invalid, and compare equal to 0).

        nash

which stops the seg fault but still get editable is not editable error. 
I have change on entry2 set to hit the changed func of entry1 so even if 
the error is thrown while entering in entry1 when I switch to entering 
in entry2 and entery is above NULL shouldn't it possibly recognize it? 
What do I need to look for that makes entry2 seen as editable? Why is 
NULL not a valid pointer? How do I get around this?

NULL is never a valid pointer - it is a valid pointer for C to store,
but it is meant to be used as an invalid pointer.  Why not just check
that entry2 is not NULL when the function is called, if you are
assumeing that entry2 is not NULL.

eg 
        assert(entry2 != NULL);
or
        if (entry2 == NULL){
                g_warning("entry2 is NULL");
                return;
        }


        nash
-- 
Brett Nash <nash nash nu>
Sometimes it's better to light a flamethrower than curse the darkness.



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