Skip to content

Commit

Permalink
Fixed crash in builtin function right() (#1099)
Browse files Browse the repository at this point in the history
* Fixed crash in builtin function right()

* Fixed ut failure
  • Loading branch information
dutor authored Oct 17, 2019
1 parent 85ae6e2 commit 6342c0a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/common/filter/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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<int64_t>(value.size())) {
length = value.size();
}
return value.substr(value.size() - length);
};
Expand Down

0 comments on commit 6342c0a

Please sign in to comment.