diff --git a/src/Functions/runningDifference.h b/src/Functions/runningDifference.h index 00874272496..db32b5f9a3f 100644 --- a/src/Functions/runningDifference.h +++ b/src/Functions/runningDifference.h @@ -46,7 +46,7 @@ private: /// It is possible to track value from previous columns, to calculate continuously across all columnss. Not implemented. template - static void process(const PaddedPODArray & src, PaddedPODArray & dst, const NullMap * null_map) + static NO_SANITIZE_UNDEFINED void process(const PaddedPODArray & src, PaddedPODArray & dst, const NullMap * null_map) { size_t size = src.size(); dst.resize(size); @@ -76,6 +76,7 @@ private: else { auto cur = src[i]; + /// Overflow is Ok. dst[i] = static_cast(cur) - prev; prev = cur; } diff --git a/tests/queries/0_stateless/01665_running_difference_ubsan.reference b/tests/queries/0_stateless/01665_running_difference_ubsan.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01665_running_difference_ubsan.sql b/tests/queries/0_stateless/01665_running_difference_ubsan.sql new file mode 100644 index 00000000000..fa09502a105 --- /dev/null +++ b/tests/queries/0_stateless/01665_running_difference_ubsan.sql @@ -0,0 +1 @@ +SELECT k, d, i FROM (SELECT t.1 AS k, t.2 AS v, runningDifference(v) AS d, runningDifference(cityHash64(t.1)) AS i FROM (SELECT arrayJoin([(NULL, 65535), ('a', 7), ('a', 3), ('b', 11), ('b', 2), ('', -9223372036854775808)]) AS t)) WHERE i = 9223372036854775807;