mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-28 10:30:03 +01:00
gsrvtarget: Silence false positive NULL pointer dereference
scan-build thinks there could be a `NULL` pointer dereference of `t->data` here. It’s wrong, so add an assertion to try and help it understand the control flow. The loop is exited as soon as a target is found whose weight is greater than or equal to a random value between 0 and the sum of all the weights in the set of remaining targets in the loop. By definition, the last target in the loop always satisfies this condition, so a target will always be chosen, and hence `t` will never be `NULL` within the loop. `t->data` will never be `NULL` by construction of the target list. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #1767
This commit is contained in:
parent
066298b6ef
commit
a1ff120a98
@ -285,6 +285,7 @@ g_srv_target_list_sort (GList *targets)
|
||||
val = g_random_int_range (0, sum + 1);
|
||||
for (t = targets; ; t = t->next)
|
||||
{
|
||||
g_assert (t != NULL && t->data != NULL);
|
||||
weight = ((GSrvTarget *)t->data)->weight;
|
||||
if (weight >= val)
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user