mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #29203 from CurtizJ/fix-ubsan
Fix integer underflow in function `quantile`
This commit is contained in:
commit
b64bbb54aa
@ -237,7 +237,7 @@ struct QuantileExactInclusive : public QuantileExact<Value>
|
|||||||
nth_element(array.begin() + prev_n, array.begin() + n - 1, array.end());
|
nth_element(array.begin() + prev_n, array.begin() + n - 1, array.end());
|
||||||
auto nth_elem = std::min_element(array.begin() + n, array.end());
|
auto nth_elem = std::min_element(array.begin() + n, array.end());
|
||||||
|
|
||||||
result[indices[i]] = static_cast<Float64>(array[n - 1]) + (h - n) * static_cast<Float64>(*nth_elem - array[n - 1]);
|
result[indices[i]] = static_cast<Float64>(array[n - 1]) + (h - n) * (static_cast<Float64>(*nth_elem) - array[n - 1]);
|
||||||
prev_n = n - 1;
|
prev_n = n - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
[-1717986918.2,1.8]
|
6
tests/queries/0_stateless/02030_quantiles_underflow.sql
Normal file
6
tests/queries/0_stateless/02030_quantiles_underflow.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
SELECT
|
||||||
|
arrayMap(y -> round(y, 1), quantilesExactInclusive(0.1, 0.9)(x)) AS q
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT arrayJoin([-2147483648, 1, 2]) AS x
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user