Re: Abend in gdk_pixbuf_new_from_file



El jue, 26 de 02 de 2004 a las 14:15, Bryan Brown escribiÃ:
Hello,

My application (built using gtk 2.x under Redhat 9) sets up a file
selection dialog, waits for the user to select a file, then tries to read
the specified file into a pixbuf.

It's abending with a segmentation fault when it calls
gdk_pixbuf_new_from_file, the user having selected a standard
png-formatted picture file.

Could you provide a backtrace? Just the first 20 lines. It could help us
to track the problem.

Here's a snippet of the relevant code:

===== begin code snip =====

GtkWidget *file_selector;
gchar     *filename;

[snip]

void
on_read_ok_button_clicked (GtkButton *button,
                           gpointer  user_data)
{
   gchar filename_local[BUFLEN] = "\0";
   GError *error;
   GdkPixbuf *pixbuf = NULL;

[snip]

   filename = (gchar *) gtk_file_selection_get_filename (
               GTK_FILE_SELECTION (file_selector));

[snip length checking]

   strcpy (filename_local, filename);
   gtk_widget_destroy (file_selector);

   pixbuf = gdk_pixbuf_new_from_file (filename_local,
                                      &error);

Nothing to do with your segfault, but could be much better and safer if
you use g_strdup() instead of strcpy. With strcopy you must provide a
buffer big enought to store the string and with g_strdup you avoid this
kind of failures.

   gchar *filename_local;
   GError *error;
   GdkPixbuf *pixbuf = NULL;

[snip]

   filename = (gchar *) gtk_file_selection_get_filename (
               GTK_FILE_SELECTION (file_selector));

[snip length checking] <- not needed anymore

   filename_local = g_strdup(filename);
   gtk_widget_destroy (file_selector);

   pixbuf = gdk_pixbuf_new_from_file (filename_local,
                                      &error);
   g_free( filename_local );


[snip]


regards
-- 
Iago Rubio                http://www.iagorubio.com          
GPGkey pgp.rediris.es id 0x909BD4DD  fingerprint =
D18A B950 5F03 BB9A DD89  AA75 FEDF 1978 909B D4DD
********** iago.rubio(AT)hispalinux.es  **********     
--------------------------------------------------

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



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