From a1ff120a989dc7c43599bd9d85718758229dec18 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 10 Apr 2024 00:08:50 +0100 Subject: [PATCH] gsrvtarget: Silence false positive NULL pointer dereference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Helps: #1767 --- gio/gsrvtarget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gio/gsrvtarget.c b/gio/gsrvtarget.c index f5f17ef64..238729b76 100644 --- a/gio/gsrvtarget.c +++ b/gio/gsrvtarget.c @@ -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;