Re: [gtk-list] What am I doing wrong?



You can't store where newpath points, because newpath
doesn't point anywhere. You are "walking around in memory",
not a good thing.  You need to allocate some place to store
into, either an array, or some memory with any of the numerous
C/glib functions,.... You're having a C problem, not a GTK+ problem.

Donna
----- Original Message -----
From: Jeff Shipman <shippy@cs.nmt.edu>
To: GTK List <gtk-list@redhat.com>
Sent: Thursday, March 30, 2000 10:15 AM
Subject: [gtk-list] What am I doing wrong?


> Ok, I've got the following function I use to enable
> or disable a menu item. However, it's causing my
> program to segfault on startup and quit depending on
> what I do. Here's my code.
>
> void change_menu_item_state(GtkItemFactory *menu, gchar *path, gboolean
> state)
> {
>    GtkWidget *tmp;
>    gchar *newpath;
>
>    /* This is necessary because gtk_item_factory_get_widget() *
>     * does not like underscores. So we rip 'em out.           */
>    while((*newpath = *path++) != '\0')
>    {
>       if(*newpath != '_')
>       {
>          newpath++;
>       }
>    }
>
> /*   printf("--%s--\n", newpath); */
>    tmp = gtk_item_factory_get_widget(menu, newpath);
>    gtk_widget_set_sensitive(tmp, state);
> }
>
> If I uncomment the printf(), my program segfaults
> right when I start the program. If I keep it commented,
> I can run the program, but then it segfaults right
> when I quit. What am I doing wrong? It's probably
> something trivial that has to do with memory allocation,
> but I'm stil pretty new at that.
>
> --
> +-----------------------------------------------------+
> | Jeff "Shippy" Shipman     E-Mail: shippy@cs.nmt.edu |
> | Computer Science Major    ICQ: 1786493              |
> | New Mexico Institute of Mining and Technology       |
> | Homepage: http://www.nmt.edu/~shippy                |
> +-----------------------------------------------------+
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
/dev/null
>
>



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