Segmentation error during optimization in a simple GTK + application?

It may be too late, but it seems curious to me that the next few lines seem to cause a segmentation error if and only if gcc optimizations are compiled, even “-O1”!

settings_dialog = gtk_dialog_new_with_buttons("gatotray Settings"
    , NULL, 0, GTK_STOCK_CANCEL, FALSE, GTK_STOCK_SAVE, TRUE, 0);
g_signal_connect(G_OBJECT(settings_dialog), "response", G_CALLBACK(gtk_widget_destroy), NULL);
g_signal_connect(G_OBJECT(settings_dialog), "destroy", G_CALLBACK(settings_destroyed), NULL);
GtkWidget *vb = gtk_dialog_get_content_area(GTK_DIALOG(settings_dialog));
GtkWidget *hb = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(hb), gtk_label_new("Background:"));
GtkWidget *cb = gtk_color_button_new();
gtk_container_add(GTK_CONTAINER(hb), cb);
gtk_container_add(GTK_CONTAINER(vb), hb);

This is the back trace:

(gdb) backtrace 
#0  0x00007ffff4d88052 in ?? () from /lib/libc.so.6
#1  0x00007ffff5304112 in g_strdup () from /lib/libglib-2.0.so.0
#2  0x00007ffff5bc799d in ?? () from /usr/lib/libgobject-2.0.so.0
#3  0x00007ffff5ba826c in g_object_new_valist ()
   from /usr/lib/libgobject-2.0.so.0
#4  0x00007ffff5ba84f1 in g_object_new () from /usr/lib/libgobject-2.0.so.0
#5  0x00007ffff78502d5 in gtk_button_new_from_stock ()
   from /usr/lib/libgtk-x11-2.0.so.0
#6  0x00007ffff787cc95 in gtk_dialog_add_button ()
   from /usr/lib/libgtk-x11-2.0.so.0
#7  0x00007ffff787cd60 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
#8  0x00007ffff787cf60 in gtk_dialog_new_with_buttons ()
   from /usr/lib/libgtk-x11-2.0.so.0
#9  0x0000000000402bb9 in show_settings_dialog () at settings.c:24
#10 0x0000000000403328 in main (argc=1, argv=0x7fffffffe2b8) at gatotray.c:286

... settings.c: 24 is exactly the first line above, it seems that "gtk_dialog_new_with_buttons" is the culprit ...

Versions:
gcc: 4.4.3
GTK +: 2.20.1

By the way, I forgot to mention that commenting on certain lines after a conflict call prevents it from occurring. In particular, the line with "gtk_container_add (GTK_CONTAINER (hb), cb);"

I tried almost all suitable combinations of GtkTypes / GTK_MACROS, it does not matter.

+5
1

: NULL, NULL, 0!

( , , ...)

GTK + :

GtkWidget*
gtk_dialog_new_with_buttons (const gchar    *title,
                             GtkWindow      *parent,
                             GtkDialogFlags  flags,
                             const gchar    *first_button_text,
                         ...);

title : Title of the dialog, or NULL. allow-none.
parent : Transient parent of the dialog, or NULL. allow-none.
flags : from GtkDialogFlags
first_button_text : stock ID or text to go in first button, or NULL. allow-none.
... : response ID for first button, then additional buttons, ending with NULL

"0", NULL:

settings_dialog = GTK_DIALOG(gtk_dialog_new_with_buttons("gatotray Settings"
    , NULL, 0, GTK_STOCK_CANCEL, FALSE, GTK_STOCK_SAVE, TRUE, 0));

... , NULL , 64- 64- , 0 32- ...

, , : , -Wall.

Myforwik Havoc P , 'NULL' "0" . , !

32- , NULL 32-, segfault. , , NULL - 0, , ++!; -)

+3

All Articles