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:
Simon McVittie 2024-07-27 18:16:13 +01:00
parent d301d16aee
commit ca7094296c

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)
#if GLIB_SIZEOF_SIZE_T > 4
new_size |= new_size >> 32;
#endif
new_size++;
if (new_size == 0) /* (overflow) Not bloody likely! */