mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32: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)
|
inline uint8_t geohashPrecision(uint8_t precision)
|
||||||
{
|
{
|
||||||
if (precision == 0 || precision > MAX_PRECISION)
|
if (precision == 0 || precision > MAX_PRECISION)
|
||||||
{
|
|
||||||
precision = MAX_PRECISION;
|
precision = MAX_PRECISION;
|
||||||
}
|
|
||||||
|
|
||||||
return precision;
|
return precision;
|
||||||
}
|
}
|
||||||
@ -281,13 +279,21 @@ GeohashesInBoxPreparedArgs geohashesInBoxPrepare(
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
longitude_min = std::max(longitude_min, LON_MIN);
|
auto saturate = [](Float64 & value, Float64 min, Float64 max)
|
||||||
longitude_max = std::min(longitude_max, LON_MAX);
|
{
|
||||||
latitude_min = std::max(latitude_min, LAT_MIN);
|
if (value < min)
|
||||||
latitude_max = std::min(latitude_max, LAT_MAX);
|
value = min;
|
||||||
|
else if (value > max)
|
||||||
|
value = max;
|
||||||
|
};
|
||||||
|
|
||||||
const auto lon_step = getSpan(precision, LONGITUDE);
|
saturate(longitude_min, LON_MIN, LON_MAX);
|
||||||
const auto lat_step = getSpan(precision, LATITUDE);
|
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.
|
/// 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;
|
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