On Tue, 25 Jun 2002, David L. Cooper II wrote:

> > First, you must know that this following code works perfectly,
> > this is a clist row selection callback. I use it for testing. But
> > there is a problem (yes...) the *y[] var isn't used, but if I
> > delete it from the code, then I get a segmentation fault when
> > executing this code. (very very strange, it seg fault as well
> > after rebooting)
> >
> > But I found another relation, if I delete the sprintf function
> > and the *y[] var, then there is no more seg fault... So I deduce
> > that sprintf func without *y[] unused var makes a seg fault.
> >
> > but I need to use sprintf func (cause I haven't itoa() func) and
> > I don't want this *y[] ghost var in my project... does somebody
> > can find where could there be a problem.. thnx

you are trying to write something to non allocated memory.
*t[3] is an array of pointers which are not initialized and could point
anywhere. when you make a sprintf on t[0] you are  writing somewhere you
don't expect. Actually you're overwriting the stack so the ghost variable
is overwritten and you're save. w/o the ghost variable you're done. :)
try to declare t as gchar *t[3][MAX_STR_LEN], otherwise allocate memory
with a malloc t[0] = (gchar*)malloc(MAX_STR_LEN); this should work.


> >
> > gboolean Callback_RowSelect(GtkWidget *w, gint lig, gint col,
> > GdkEvent *ev, gpointer d)
> > {
> >     gchar *y[3];
> >     gchar *t[3];
> >     gint x=0;
> >
> >     GtkWidget *dList = gtk_object_get_data(GTK_OBJECT(EditWin),"pList");
> >
> >     gtk_clist_clear(GTK_CLIST(dList));
> >
> >     while(MyStruct[x].pNum)
> >     {
> >             sprintf(t[0],"%i",MyStruct[x].pNum); //converts a
> > gint into gchar
> >             t[1]=MyStruct[x].pName;
> >             t[2]=MyStruct[x].pPos;
> >
> >             gtk_clist_append(GTK_CLIST(dList),t);
> >             x++;
> >     }
> >     return TRUE;
> > }
> > _______________________________________________
> > gtk-list mailing list
> > [EMAIL PROTECTED]
> > http://mail.gnome.org/mailman/listinfo/gtk-list
>
> _______________________________________________
> gtk-list mailing list
> [EMAIL PROTECTED]
> http://mail.gnome.org/mailman/listinfo/gtk-list
>

 ____                 _____
|  _ \  ___ ___  _ __| ____|
| | | |/ __/ _ \| '__|  _|
| |_| | (_| (_) | |  | |___
|____/ \___\___/|_|  |_____|


_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to