mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-25 19:52:10 +01:00
garray: Rewrite binary search calculation to avoid integer overflow
If `right` and `left` are both near `G_MAXUINT`, it’s possible for the addition to overflow, even if the eventual result would fit in a `guint`. Avoid that by operating on the difference instead. The difference is guaranteed to be positive due to the prior `left <= right` check. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
bc0fcddc18
commit
ec61daf503
@ -845,7 +845,7 @@ g_array_binary_search (GArray *array,
|
||||
|
||||
while (left <= right)
|
||||
{
|
||||
middle = (left + right) / 2;
|
||||
middle = left + (right - left) / 2;
|
||||
|
||||
val = compare_func (_array->data + (_array->elt_size * middle), target);
|
||||
if (val < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user