[Glade-users] libxml and treeview - how to read in more than one entries from an xml file



On Tue, Apr 8, 2008 at 10:42 AM, Atmadarshini devi dasi
<atmadarshini_dd at yahoo.com> wrote:
Hi there

Could you sort of explain what you mean? I dont understand.

You allocate address once:

   address = (AddressBook*)malloc(sizeof(AddressBook));

And in  "int addressbook_get_addresses_from_xml_file(char *filename)"
you never return address.

So, what you need is to have a GList * of allocated addresses,
otherwise you are just overwriting the pointers in address every
time you do:
   strcpy(address->cellphone, child->content);

Moreover, dont use strcpy here, if adress->cellphone really
is a char array then use strncpy() to make sure you stay within
the bounds of your char array.

But unless your app is really really really mission critical and needs
to know exactly how much memory its going to use at startup time,
I'd say everybody today is using allocated strings, i.e. you'd want:

   address->cellphone = g_strdup (BAD_CAST (child->content));

Also, try to stay on the glib slab, i.e. use allocators like g_new, g_malloc
and g_strdup.

Cheers,
                  -Tristan




thanks




Tristan Van Berkom <tristan.van.berkom at gmail.com> wrote:
 On Tue, Apr 8, 2008 at 9:43 AM, Atmadarshini devi dasi
 wrote:
Hi there

I am working with glade, gtktreeview and libxml. What i am trying to do is
that from an xml file, I am trying to put things into my treeview. My
treeview for instance has three columns such as Lastname, Firstname,
cellphone.

I dont see how this code could work, even if your parsing function
even ever returned the address it allocated, it only ever allocates one
and simply overwrites the strings each new address it parses, leaking
the old strings.

Cheers,
 -Tristan




 ________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster
Total Access, No Cost.




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