Merge branch 'wip/smcv/ubsan' into 'main'

Avoid undefined behaviour in a few simple cases

See merge request GNOME/gtk!7508
This commit is contained in:
Matthias Clasen 2024-07-28 20:00:06 +00:00
commit 1b53359cd3
4 changed files with 9 additions and 6 deletions

View File

@ -207,7 +207,8 @@ gdk_dmabuf_formats_new (GdkDmabufFormat *formats,
self->n_formats = n_formats;
self->formats = g_new (GdkDmabufFormat, n_formats);
memcpy (self->formats, formats, n_formats * sizeof (GdkDmabufFormat));
if (n_formats != 0)
memcpy (self->formats, formats, n_formats * sizeof (GdkDmabufFormat));
return self;
}

View File

@ -446,9 +446,9 @@ gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl,
for (i = 0; i < sizeof (GtkStateFlags) * 8; i++)
{
if (decl->state & (1 << i))
if (decl->state & (1u << i))
{
const char *name = gtk_css_pseudoclass_name (1 << i);
const char *name = gtk_css_pseudoclass_name (1u << i);
g_assert (name);
g_string_append_c (string, ':');
g_string_append (string, name);

View File

@ -110,7 +110,8 @@ gtk_symbolic_paintable_snapshot_symbolic (GtkSymbolicPaintable *paintable,
[GTK_SYMBOLIC_COLOR_SUCCESS] = { 0.3046921492332342,0.6015716792553597, 0.023437857633325704, 1.0 }
};
memcpy (real_colors, colors, sizeof (GdkRGBA) * n_colors);
if (n_colors != 0)
memcpy (real_colors, colors, sizeof (GdkRGBA) * n_colors);
iface->snapshot_symbolic (paintable, snapshot, width, height, real_colors, 4);
}

View File

@ -157,8 +157,9 @@ gtk_tim_sort_ensure_capacity (GtkTimSort *self,
new_size |= new_size >> 4;
new_size |= new_size >> 8;
new_size |= new_size >> 16;
if (sizeof(new_size) > 4)
new_size |= new_size >> 32;
#if GLIB_SIZEOF_SIZE_T > 4
new_size |= new_size >> 32;
#endif
new_size++;
if (new_size == 0) /* (overflow) Not bloody likely! */