Fix UBSan report in rounding to years intervals

This commit is contained in:
Alexey Milovidov 2021-03-15 20:36:49 +03:00
parent eaeb4a3bf0
commit badd5165da
3 changed files with 9 additions and 1 deletions

View File

@ -807,7 +807,14 @@ public:
return toFirstDayNumOfYear(v);
const LUTIndex i = toLUTIndex(v);
return toDayNum(years_lut[lut[i].year / years * years - DATE_LUT_MIN_YEAR]);
UInt16 year = lut[i].year / years * years;
/// For example, rounding down 1925 to 100 years will be 1900, but it's less than min supported year.
if (unlikely(year < DATE_LUT_MIN_YEAR))
year = DATE_LUT_MIN_YEAR;
return toDayNum(years_lut[year - DATE_LUT_MIN_YEAR]);
}
inline ExtendedDayNum toStartOfQuarterInterval(ExtendedDayNum d, UInt64 quarters) const

View File

@ -0,0 +1 @@
SELECT toStartOfInterval(toDateTime(-9223372036854775808), toIntervalYear(100), 'Europe/Moscow') FORMAT Null;