Re: clist mystery



On Wed, Mar 14, 2001 at 07:00:50AM -0500 Mike wrote:

HI.

I think the problem could be that Unix has a different way to store
more-dimensional array internally. The solution could be that you use a one
dimenional array: gchar* list_data[2];
btw. why using gchar* list_data[1][2];?

I also fixed some other stuff that could be a problem one day.

Hello, 

I've got a piece of code which runs fine on my linux box but dumps core 
reliably on my sparcstation. The sparc has gtk+ 1.2.6 and the linux box has 
1.2.8 Here is the code:

void load_script_list(gpointer clist1)
{
    extern script_text *active_script_data;    

    gchar *list_data[1][2];    

Use: gchar *list_data[2];

    gint  script_running;
    gint  x;
    gchar *script_date;

    script_running = get_status_script_page();

    if ( script_running )
    {
         script_date = g_malloc(256);
         sprintf(script_date, "%s/%s/%s", active_script_data->month,          
   
active_script_data->date, active_script_data->year);

You should use here: script_data = g_strdup_printf("%s/%s/%s", ....);
or use the malloc and snprintf();

    }
    else
    {
         script_date = g_malloc(256);
         strcpy(script_date, "none");

Smae here: just use: script_date = strdup("none");

    }

    list_data[0][1] = g_malloc( (strlen(script_date) + 1) );
    list_data[0][0] = g_malloc( (strlen("Date ") + 1) );
    strcpy(list_data[0][0], "Date ");
    strcpy(list_data[0][1], script_date);

Use: list_data[0] = strdup("Date ");
     list_data[1] = strdup(script_date);    

    gtk_clist_append( (GtkCList *)clist1, list_data[0]);

gtk_clist_append(GTK_CLIST(clist1), list_data);

<snip>

[and free script_date...]

}

Here is the core dump:

#0  0xeecb2988 in strlen () from /usr/lib/libc.so.1
#1  0xef1218bc in g_strdup (str=0x5 <Address 0x5 out of bounds>) at 
gstrfuncs.c:56
#2  0xef352d50 in set_cell_contents (clist=0xdb3c8, clist_row=0xdb9e0, 
column=2, type=GTK_CELL_TEXT, text=0x5 <Address 0x5 out of bounds>,
    spacing=0 '\000', pixmap=0x0, mask=0x0) at gtkclist.c:2469
#3  0xef3537fc in real_insert_row (clist=0xdb3c8, row=0, text=0xefffe5d0) at 
gtkclist.c:2640
#4  0xef353358 in gtk_clist_append (clist=0xdb3c8, text=0xefffe5d0) at 
gtkclist.c:2578
#5  0x58de4 in load_script_list (clist1=0xdb3c8) at script_page.c:997
#6  0x5a7b8 in reload_previous_script (w=0xdb680, user_data=0xda2b0) at 
script_page_callbacks.c:419 
<snip>

The clist loads up fine the first time the function is called, but when I 
want to change the data in the list I clear it then call the function again 
and it dies on the gtk_clist_append() call. As you can see it thinks that the 
pointer to the text for column 2 is out of bounds????? I even tried it with 
static text and I get the same thing every time.... as i said it works fine 
under the Linux box. It seems so simple I must be overlooking something. Is 
this a problem with 1.2.6? Do i need to update to 1.2.8? The clist example 
that comes with the source for 1.2.6 works fine on the sparc and it's 
actually doing the exact same thing I'm trying to do, load a list, clear the
list and reload it.

I'm stumped.

Mike

_______________________________________________
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]