[glib: 1/2] gdatetime: Widen a variable before multiplication
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gdatetime: Widen a variable before multiplication
- Date: Tue, 18 Aug 2020 09:49:16 +0000 (UTC)
commit b0be67cc3fce2fa7019cfb769a6ae22ba3bd6d56
Author: Philip Withnall <withnall endlessm com>
Date: Tue Aug 18 10:22:00 2020 +0100
gdatetime: Widen a variable before multiplication
Otherwise it could possibly overflow on 32-bit machines if `year` is
high enough, although I don’t think that’s possible because of limits
applied on it by callers. This should shut Coverity up though.
The limits applied by callers could be circumvented by calling (say)
`g_date_time_add_years()` multiple times. That’s a bug, but not one I’m
going to fix today.
Coverity CID: #1159479
Signed-off-by: Philip Withnall <withnall endlessm com>
glib/gdatetime.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index f85afab0c..fab60c441 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -598,7 +598,7 @@ ymd_to_days (gint year,
{
gint64 days;
- days = (year - 1) * 365 + ((year - 1) / 4) - ((year - 1) / 100)
+ days = ((gint64) year - 1) * 365 + ((year - 1) / 4) - ((year - 1) / 100)
+ ((year - 1) / 400);
days += days_in_year[0][month - 1];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]