Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#383 Fix widget allocation/requisition crashes

open
nobody
None
5
2011-06-12
2011-06-02
Nicola Fontana
No

gtk_widget_get_allocation() expects a yet allocated struct pointer. The
previous way to handle this will likely generate a segmentation fault:

/* Wrong */
GtkAllocation *allocation;
gtk_widget_get_allocation(widget, allocation);
...

/* Right 1 */
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
...

/* Right 2 */
GtkAllocation *allocation = g_new(GtkAllocation, 1);
gtk_widget_get_allocation(widget, allocation);
...
g_free(allocation);

Discussion

  • Nicola Fontana
    Nicola Fontana
    2011-06-12

    Fix widget requisition/allocation issues (bug #3306376)

    gtk_widget_get_allocation() expects a yet allocated struct pointer, and
    the same holds for gtk_widget_get_requisition(). The previous way to
    call these APIs will likely generate segmentation fault:

    /* Wrong */
    GtkAllocation *allocation;
    gtk_widget_get_allocation(widget, allocation);
    ...

    /* Right 1 */
    GtkAllocation allocation;
    gtk_widget_get_allocation(widget, &allocation);
    ...

    /* Right 2 */
    GtkAllocation *allocation = g_new(GtkAllocation, 1);
    gtk_widget_get_allocation(widget, allocation);
    ...
    g_free(allocation);

     
  • Nicola Fontana
    Nicola Fontana
    2011-06-12

    • summary: Fix widget allocation issues for GTK+ >= 2.18.0 --> Fix widget allocation/requisition crashes