From 1d6c46a0acd05fc6199d7542c3908772631ff5e0 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 28 Apr 2022 11:14:18 +0100 Subject: [PATCH] gdatetime: Rework array indexing to satisfy scan-build This introduces no functional changes, but reworks the array indexing so that scan-build has a better idea about the array bounds. This squashes the scan-build warning: ``` ../../../../source/glib/glib/gdatetime.c:2292:20: warning: The left operand of '>=' is a garbage value [core.UndefinedBinaryOperatorResult] if (days [i] >= day_of_year) ~~~~~~~~ ^ ``` Signed-off-by: Philip Withnall Helps: #1767 --- glib/gdatetime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/glib/gdatetime.c b/glib/gdatetime.c index 0ec390c94..7d3d27213 100644 --- a/glib/gdatetime.c +++ b/glib/gdatetime.c @@ -2279,19 +2279,19 @@ g_date_time_get_day_of_month (GDateTime *datetime) { gint day_of_year, i; - const guint16 *days; + guint is_leap; guint16 last = 0; g_return_val_if_fail (datetime != NULL, 0); - days = days_in_year[GREGORIAN_LEAP (g_date_time_get_year (datetime)) ? 1 : 0]; + is_leap = GREGORIAN_LEAP (g_date_time_get_year (datetime)) ? 1 : 0; g_date_time_get_week_number (datetime, NULL, NULL, &day_of_year); for (i = 1; i <= 12; i++) { - if (days [i] >= day_of_year) + if (days_in_year[is_leap][i] >= day_of_year) return day_of_year - last; - last = days [i]; + last = days_in_year[is_leap][i]; } g_warn_if_reached ();