From b9c4820bdd5f0152a9ba077308d521edb782eff9 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 2 Sep 2018 06:52:04 +0300 Subject: [PATCH] Addition to prev. revision [#CLICKHOUSE-2] --- dbms/src/Functions/FunctionsStringSearch.cpp | 12 ++++++++---- dbms/src/Functions/FunctionsVisitParam.h | 3 ++- dbms/src/Functions/GatherUtils/Algorithms.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dbms/src/Functions/FunctionsStringSearch.cpp b/dbms/src/Functions/FunctionsStringSearch.cpp index 4545aa25784..2c8b575b6b8 100644 --- a/dbms/src/Functions/FunctionsStringSearch.cpp +++ b/dbms/src/Functions/FunctionsStringSearch.cpp @@ -191,7 +191,8 @@ struct PositionImpl ++i; } - memset(&res[i], 0, (res.size() - i) * sizeof(res[0])); + if (i < res.size()) + memset(&res[i], 0, (res.size() - i) * sizeof(res[0])); } /// Search for substring in string. @@ -389,7 +390,8 @@ struct MatchImpl } /// Tail, in which there can be no substring. - memset(&res[i], revert, (res.size() - i) * sizeof(res[0])); + if (i < res.size()) + memset(&res[i], revert, (res.size() - i) * sizeof(res[0])); } else { @@ -407,7 +409,8 @@ struct MatchImpl { if (!regexp->getRE2()) /// An empty regexp. Always matches. { - memset(res.data(), 1, size * sizeof(res[0])); + if (size) + memset(res.data(), 1, size * sizeof(res[0])); } else { @@ -488,7 +491,8 @@ struct MatchImpl ++i; } - memset(&res[i], revert, (res.size() - i) * sizeof(res[0])); + if (i < res.size()) + memset(&res[i], revert, (res.size() - i) * sizeof(res[0])); } } } diff --git a/dbms/src/Functions/FunctionsVisitParam.h b/dbms/src/Functions/FunctionsVisitParam.h index 897414e6498..82bf8946e7c 100644 --- a/dbms/src/Functions/FunctionsVisitParam.h +++ b/dbms/src/Functions/FunctionsVisitParam.h @@ -194,7 +194,8 @@ struct ExtractParamImpl ++i; } - memset(&res[i], 0, (res.size() - i) * sizeof(res[0])); + if (res.size() > i) + memset(&res[i], 0, (res.size() - i) * sizeof(res[0])); } static void constant_constant(const std::string & data, std::string needle, ResultType & res) diff --git a/dbms/src/Functions/GatherUtils/Algorithms.h b/dbms/src/Functions/GatherUtils/Algorithms.h index fee172ce394..e4027d54cdf 100644 --- a/dbms/src/Functions/GatherUtils/Algorithms.h +++ b/dbms/src/Functions/GatherUtils/Algorithms.h @@ -105,7 +105,7 @@ inline ALWAYS_INLINE void writeSlice(const Slice & slice, NullableArraySink(sink));