Re: glist



I'm not yet so familiar with glist but try to answer this anyway ;-)

On Fri, Apr 02, 1999 at 09:13:56PM +0200, ZioBudda wrote:
> Hi, I have this struct:
> struct __db_table {
>  GList *attrib;
>  GString *name_table;
>  int mod; /* attributo che indica se e' stata modificata */
> };
> 
> and with this code I crate a double-link list:
> tmp_db_table.attrib = NULL;
>     tmp_db_table.name_table = g_string_new(g_db_return_item(db,i,0));
>     table2 = g_list_append(table2, &tmp_db_table);

Beware, You are only storeing the *adress* of the struct in the list
so the tmp_db_table must live as longe as You plan to use the list!

if tmp_db_table is auto and You keep acessing the list after retuning
from the function where you added this entry You may later get more or
less random stack coruption. Bad, bad, bad bug....

Might be bether to use dynamicly allocated db_table?

> (gchar *)table2->data.name_table

try
   ((struct __db_table *) table2->data)->name_table

or something simular ;-)

HTH /Lars



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