Re: read() and label funkiness



From: "Havoc Pennington" <hp@redhat.com>
> 
> "Ben K" <kynneb@hotmail.com> writes: 
> >     pppd_fd = open ("/etc/ppp/pppd.status", O_RDONLY); file://get the fd
> >     read(pppd_fd, label_text_ptr, 25);//read 25 bytes
> >     gtk_label_set_text(GTK_LABEL( (GtkWidget*)data ), label_text_ptr);
> 
> read() isn't going to nul-terminate your string. Use calloc() or
> g_malloc0() instead of malloc(). (Remember to use g_free() if you use
> g_malloc0()).
> 

You're also never close the file, so eventually the open will fail and
you'll be reading from an invalid fd.

Dom.






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