From b0be67cc3fce2fa7019cfb769a6ae22ba3bd6d56 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 18 Aug 2020 10:22:00 +0100 Subject: [PATCH] gdatetime: Widen a variable before multiplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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];