mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Fix UBSan report in geoHashesInBox
This commit is contained in:
parent
9f8f908779
commit
9930bb0bf6
@ -216,9 +216,7 @@ inline Float64 getSpan(uint8_t precision, CoordType type)
|
||||
inline uint8_t geohashPrecision(uint8_t precision)
|
||||
{
|
||||
if (precision == 0 || precision > MAX_PRECISION)
|
||||
{
|
||||
precision = MAX_PRECISION;
|
||||
}
|
||||
|
||||
return precision;
|
||||
}
|
||||
@ -281,13 +279,21 @@ GeohashesInBoxPreparedArgs geohashesInBoxPrepare(
|
||||
return {};
|
||||
}
|
||||
|
||||
longitude_min = std::max(longitude_min, LON_MIN);
|
||||
longitude_max = std::min(longitude_max, LON_MAX);
|
||||
latitude_min = std::max(latitude_min, LAT_MIN);
|
||||
latitude_max = std::min(latitude_max, LAT_MAX);
|
||||
auto saturate = [](Float64 & value, Float64 min, Float64 max)
|
||||
{
|
||||
if (value < min)
|
||||
value = min;
|
||||
else if (value > max)
|
||||
value = max;
|
||||
};
|
||||
|
||||
const auto lon_step = getSpan(precision, LONGITUDE);
|
||||
const auto lat_step = getSpan(precision, LATITUDE);
|
||||
saturate(longitude_min, LON_MIN, LON_MAX);
|
||||
saturate(longitude_max, LON_MIN, LON_MAX);
|
||||
saturate(latitude_min, LAT_MIN, LAT_MAX);
|
||||
saturate(latitude_max, LAT_MIN, LAT_MAX);
|
||||
|
||||
Float64 lon_step = getSpan(precision, LONGITUDE);
|
||||
Float64 lat_step = getSpan(precision, LATITUDE);
|
||||
|
||||
/// Align max to the right (or up) border of geohash grid cell to ensure that cell is in result.
|
||||
Float64 lon_min = floor(longitude_min / lon_step) * lon_step;
|
||||
|
1
tests/queries/0_stateless/01684_geohash_ubsan.reference
Normal file
1
tests/queries/0_stateless/01684_geohash_ubsan.reference
Normal file
@ -0,0 +1 @@
|
||||
['ypzpgxczgpyr']
|
1
tests/queries/0_stateless/01684_geohash_ubsan.sql
Normal file
1
tests/queries/0_stateless/01684_geohash_ubsan.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT geohashesInBox(100.0000991821289, 100.0000991821289, 1000.0001220703125, 1000.0001220703125, 0);
|
Loading…
Reference in New Issue
Block a user