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>
This commit is contained in:
Philip Withnall 2020-08-18 10:22:00 +01:00
parent c50fb4f317
commit b0be67cc3f

View File

@ -598,7 +598,7 @@ ymd_to_days (gint year,
{ {
gint64 days; 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); + ((year - 1) / 400);
days += days_in_year[0][month - 1]; days += days_in_year[0][month - 1];