Skip to content

gtkimagedefinition: Check array bounds

jhbuild build gtk+-3 with GCC 12 fails with:

In function ‘gtk_image_definition_ref’,
    inlined from ‘gtk_image_definition_new_empty’
    at ../../../../jhbuild/checkout/gtk+-3/gtk/gtkimagedefinition.c:107:10:
../../../../jhbuild/checkout/gtk+-3/gtk/gtkimagedefinition.c:241:13: error:
    array subscript ‘GtkImageDefinition {aka union _GtkImageDefinition}[0]’
    is partly outside array bounds of ‘GtkImageDefinitionEmpty[1]’
    {aka ‘struct _GtkImageDefinitionEmpty[1]’} [-Werror=array-bounds]
  241 |   def->empty.ref_count++;
      |   ~~~~~~~~~~^~~~~~~~~~
../../../../jhbuild/checkout/gtk+-3/gtk/gtkimagedefinition.c:
    In function ‘gtk_image_definition_new_empty’:
../../../../jhbuild/checkout/gtk+-3/gtk/gtkimagedefinition.c:105:34: note:
object ‘empty’ of size 8
  105 |   static GtkImageDefinitionEmpty empty = { GTK_IMAGE_EMPTY, 1 };
      |                                  ^~~~~

and many similar errors.

Fix it by casting GtkImageDefinition to GtkImageDefinitionEmpty or similar, as appropriate.

Essentially backports 4dcd02e8 from main to gtk-3-24.

Merge request reports