mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Fix UBSan report in arrayDifference
This commit is contained in:
parent
abb7c88b80
commit
1c55be261c
@ -47,6 +47,29 @@ struct ArrayDifferenceImpl
|
||||
}
|
||||
|
||||
|
||||
template <typename Element, typename Result>
|
||||
static void NO_SANITIZE_UNDEFINED impl(const Element * __restrict src, Result * __restrict dst, size_t begin, size_t end)
|
||||
{
|
||||
/// First element is zero, then the differences of ith and i-1th elements.
|
||||
|
||||
Element prev{};
|
||||
for (size_t pos = begin; pos < end; ++pos)
|
||||
{
|
||||
if (pos == begin)
|
||||
{
|
||||
dst[pos] = 0;
|
||||
prev = src[pos];
|
||||
}
|
||||
else
|
||||
{
|
||||
Element curr = src[pos];
|
||||
dst[pos] = curr - prev;
|
||||
prev = curr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename Element, typename Result>
|
||||
static bool executeType(const ColumnPtr & mapped, const ColumnArray & array, ColumnPtr & res_ptr)
|
||||
{
|
||||
@ -73,14 +96,10 @@ struct ArrayDifferenceImpl
|
||||
size_t pos = 0;
|
||||
for (auto offset : offsets)
|
||||
{
|
||||
// skip empty arrays
|
||||
if (pos < offset)
|
||||
{
|
||||
res_values[pos] = 0;
|
||||
for (++pos; pos < offset; ++pos)
|
||||
res_values[pos] = static_cast<Result>(data[pos]) - static_cast<Result>(data[pos - 1]);
|
||||
}
|
||||
impl(data.data(), res_values.data(), pos, offset);
|
||||
pos = offset;
|
||||
}
|
||||
|
||||
res_ptr = ColumnArray::create(std::move(res_nested), array.getOffsetsPtr());
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
[0,9223372036854710272]
|
@ -0,0 +1,2 @@
|
||||
-- Overflow is Ok and behaves as the CPU does it.
|
||||
SELECT arrayDifference([65536, -9223372036854775808]);
|
Loading…
Reference in New Issue
Block a user