mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-09 18:30:08 +00:00
gtktimsort: Avoid undefined behaviour on 32-bit
Shifting a 32-bit type by 32 bits is formally undefined behaviour, even if it happens in code that is unreachable at runtime. Use a compile-time check against GLib's GLIB_SIZEOF_SIZE_T, instead of hoping a runtime check will be optimized away. Signed-off-by: Simon McVittie <smcv@debian.org>
This commit is contained in:
parent
d301d16aee
commit
ca7094296c
@ -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)
|
||||
#if GLIB_SIZEOF_SIZE_T > 4
|
||||
new_size |= new_size >> 32;
|
||||
#endif
|
||||
|
||||
new_size++;
|
||||
if (new_size == 0) /* (overflow) Not bloody likely! */
|
||||
|
Loading…
Reference in New Issue
Block a user