From 5b4759acd97a80a2d162ec5df7385ac783a205eb Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Fri, 1 Sep 2017 17:32:12 +0300 Subject: [PATCH] changed sibstring behaviour for offset < -string_lenght [#CLICKHOUSE-2090] --- dbms/src/Functions/GatherUtils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbms/src/Functions/GatherUtils.h b/dbms/src/Functions/GatherUtils.h index 6543e2bbeab..4865583907c 100644 --- a/dbms/src/Functions/GatherUtils.h +++ b/dbms/src/Functions/GatherUtils.h @@ -296,7 +296,7 @@ struct StringSource { size_t elem_size = offsets[row_num] - prev_offset - 1; if (offset > elem_size) - return {&elements[prev_offset], elem_size}; + return {&elements[prev_offset], length + elem_size > offset ? std::min(elem_size, length + elem_size - offset) : 0}; return {&elements[prev_offset + elem_size - offset], std::min(length, offset)}; } }; @@ -375,7 +375,7 @@ struct FixedStringSource Slice getSliceFromRight(size_t offset, size_t length) const { if (offset > string_size) - return {pos, string_size}; + return {pos, length + string_size > offset ? std::min(string_size, length + string_size - offset) : 0}; return {pos + string_size - offset, std::min(length, offset)}; } };