From 6342c0afbf86d7f7f68f8219c39e489321a57eff Mon Sep 17 00:00:00 2001 From: dutor <440396+dutor@users.noreply.github.com> Date: Thu, 17 Oct 2019 10:13:07 +0800 Subject: [PATCH] Fixed crash in builtin function right() (#1099) * Fixed crash in builtin function right() * Fixed ut failure --- src/common/filter/FunctionManager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/filter/FunctionManager.cpp b/src/common/filter/FunctionManager.cpp index baf2aa56367..cb7dc7a3ba5 100644 --- a/src/common/filter/FunctionManager.cpp +++ b/src/common/filter/FunctionManager.cpp @@ -314,8 +314,8 @@ FunctionManager::FunctionManager() { attr.body_ = [] (const auto &args) { auto value = Expression::asString(args[0]); auto length = Expression::asInt(args[1]); - if (length < 0) { - length = 0; + if (length <= 0) { + return std::string(); } return value.substr(0, length); }; @@ -328,7 +328,10 @@ FunctionManager::FunctionManager() { auto value = Expression::asString(args[0]); auto length = Expression::asInt(args[1]); if (length <= 0) { - length = 0; + return std::string(); + } + if (length > static_cast(value.size())) { + length = value.size(); } return value.substr(value.size() - length); };