mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Fix UBSan report in intDiv #21769
This commit is contained in:
parent
49cdd5e434
commit
c94841bca5
@ -49,11 +49,10 @@ struct DivideIntegralByConstantImpl
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
/// Division by -1. By the way, we avoid FPE by division of the largest negative number by -1.
|
||||
/// And signed integer overflow is well defined in C++20.
|
||||
if (unlikely(is_signed_v<B> && b == -1))
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
c_pos[i] = -a_pos[i];
|
||||
c_pos[i] = -make_unsigned_t<A>(a_pos[i]); /// Avoid UBSan report in signed integer overflow.
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
-9223372036854775807
|
||||
-9223372036854775808
|
||||
9223372036854775807
|
||||
9223372036854775806
|
||||
9223372036854775805
|
||||
9223372036854775804
|
||||
9223372036854775803
|
||||
9223372036854775802
|
||||
9223372036854775801
|
||||
9223372036854775800
|
@ -0,0 +1 @@
|
||||
SELECT intDiv(toInt64(number), -1) FROM numbers(9223372036854775807, 10);
|
Loading…
Reference in New Issue
Block a user