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 <pwithnall@endlessos.org>

Helps: #1767
This commit is contained in:
Philip Withnall 2022-04-28 11:14:18 +01:00
parent 7f83151ac0
commit 1d6c46a0ac

View File

@ -2279,19 +2279,19 @@ g_date_time_get_day_of_month (GDateTime *datetime)
{ {
gint day_of_year, gint day_of_year,
i; i;
const guint16 *days; guint is_leap;
guint16 last = 0; guint16 last = 0;
g_return_val_if_fail (datetime != NULL, 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); g_date_time_get_week_number (datetime, NULL, NULL, &day_of_year);
for (i = 1; i <= 12; i++) 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; return day_of_year - last;
last = days [i]; last = days_in_year[is_leap][i];
} }
g_warn_if_reached (); g_warn_if_reached ();