[glib: 5/9] gdatetime: Rework array indexing to satisfy scan-build
- From: Sebastian DrĂśge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 5/9] gdatetime: Rework array indexing to satisfy scan-build
- Date: Thu, 28 Apr 2022 11:07:36 +0000 (UTC)
commit 1d6c46a0acd05fc6199d7542c3908772631ff5e0
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Apr 28 11:14:18 2022 +0100
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
glib/gdatetime.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 0ec390c94a..7d3d272138 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 ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]