mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Fix ubsan bug
This commit is contained in:
parent
51aaee95e3
commit
aee3c9651b
@ -97,7 +97,9 @@ public:
|
||||
auto value = src_data[i];
|
||||
if (value < 0)
|
||||
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Expected a non-negative integer, got: {}", std::to_string(value));
|
||||
dst_data[i] = static_cast<RawReturnType>(value) - static_cast<RawReturnType>(ToDaysSinceYearZeroImpl::DAYS_BETWEEN_YEARS_0_AND_1970);
|
||||
/// prevent potential signed integer overflows (aka. undefined behavior) with Date32 results
|
||||
auto value_uint64 = static_cast<UInt64>(value); /// NOLINT(bugprone-signed-char-misuse,cert-str34-c)
|
||||
dst_data[i] = static_cast<RawReturnType>(value_uint64 - ToDaysSinceYearZeroImpl::DAYS_BETWEEN_YEARS_0_AND_1970);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -18,5 +18,8 @@
|
||||
719529 719529 1970-01-02 1970-01-02 1970-01-02 1970-01-02
|
||||
-- NULL handling
|
||||
\N \N
|
||||
-- ubsan bug
|
||||
2299-12-31
|
||||
2299-12-31
|
||||
-- Alias
|
||||
1973-10-01
|
||||
|
@ -33,5 +33,9 @@ SELECT toUInt64(719529) AS u, toInt64(719529) AS s, fromDaysSinceYearZero(u), fr
|
||||
SELECT '-- NULL handling';
|
||||
SELECT fromDaysSinceYearZero(NULL), fromDaysSinceYearZero32(NULL);
|
||||
|
||||
SELECT '-- ubsan bugs';
|
||||
SELECT fromDaysSinceYearZero32(2147483648);
|
||||
SELECT fromDaysSinceYearZero32(3);
|
||||
|
||||
SELECT '-- Alias';
|
||||
SELECT FROM_DAYS(1);
|
||||
|
Loading…
Reference in New Issue
Block a user