Glib problem: trying to use gpointer pointing to a structure in a GList. Getting segfault



Hi Folks:

	I'm getting a problem (maybe I'm messing things up) when
using gpointer in a GList to point a structure. When it is
pointing to a gchar everything works fine.
	Segfault occurs when calling g_print() :

Program received signal SIGSEGV, Segmentation fault.
0x4000c2bc in fixup () from /lib/ld-linux.so.2
(gdb) where
#0  0x4000c2bc in fixup () from /lib/ld-linux.so.2
#1  0x4000c270 in _dl_runtime_resolve () from /lib/ld-linux.so.2
#2  0x4005a810 in g_strdup_vprintf () from /usr/lib/libglib-2.0.so.0
#3  0x40050394 in g_print () from /usr/lib/libglib-2.0.so.0
#4  0x080486cc in main (argc=1, argv=0xbffff574) at glist.c:32
#5  0x420156a4 in __libc_start_main () from /lib/tls/libc.so.6
(gdb) up 1
#1  0x4000c270 in _dl_runtime_resolve () from /lib/ld-linux.so.2
(gdb) up 1
#2  0x4005a810 in g_strdup_vprintf () from /usr/lib/libglib-2.0.so.0
(gdb) up 1
#3  0x40050394 in g_print () from /usr/lib/libglib-2.0.so.0
(gdb) up 1
#4  0x080486cc in main (argc=1, argv=0xbffff574) at glist.c:32
32                      g_print("%s\n",record->data);
(gdb) print record->data
$1 = (gchar *) 0x804a168 "Brasilino"


	record->data is gchar* :-))

	I've tested against glib-2.2.1 (RedHat 9 stock rpm) and
self-compiled glib 2.2.2.

Any tip or help?
Thanks a lot in advance



====== cut here ===============

#include <stdio.h>
#include <string.h>
#include <glib.h>

int main(int argc, char **argv)
{

        GList *dlist = NULL, *list = NULL;
        guint length,i;
        struct {
                guint index;
                gchar *data;
        } *record;

        record->data = g_malloc(strlen("Lucas")+1);
        g_strlcpy(record->data,"Lucas",strlen("Lucas")+1);
        dlist = g_list_append(dlist, record);

        record->data = g_malloc(strlen("Brasilino")+1);
        g_strlcpy(record->data,"Brasilino", strlen("Brasilino")+1);
        dlist = g_list_append(dlist, record);

        length = g_list_length(dlist);

        g_printf("%d \n",length);

        record = NULL;
        list = g_list_first(dlist);
        while(list)
        {
                record = list->data;
                g_print("%s\n",record->data);
                list = list->next;
    }
}

================

--

[]'s
Lucas Brasilino
brasilino recife pe gov br
http://www.recife.pe.gov.br
Emprel -	Empresa Municipal de Informatica (pt_BR)
		Municipal Computing Enterprise (en_US)
Recife - Pernambuco - Brasil
Fone: +55-81-34167078




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