Skip to content

Commit

Permalink
Fix crash of list related functions (vesoft-inc#2467)
Browse files Browse the repository at this point in the history
small delete

Co-authored-by: kyle.cao <[email protected]>
  • Loading branch information
nebula-bots and czpmango authored Mar 3, 2023
1 parent 7f3a93a commit 0f6aa08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/common/function/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2033,8 +2033,11 @@ FunctionManager::FunctionManager() {
return v.vid;
}
case Value::Type::LIST: {
const auto &listVal = args[0].get().getList();
auto &lastVal = listVal.values.back();
const auto &listVal = args[0].get().getList().values;
if (listVal.empty()) {
return Value::kNullBadType;
}
auto &lastVal = listVal.back();
if (lastVal.isEdge()) {
return lastVal.getEdge().dst;
} else if (lastVal.isVertex()) {
Expand Down Expand Up @@ -2167,7 +2170,8 @@ FunctionManager::FunctionManager() {
return Value::kNullValue;
}
case Value::Type::LIST: {
return args[0].get().getList().values.front();
const auto &items = args[0].get().getList().values;
return items.empty() ? Value::kNullValue : items.front();
}
default: {
return Value::kNullBadType;
Expand All @@ -2186,7 +2190,8 @@ FunctionManager::FunctionManager() {
return Value::kNullValue;
}
case Value::Type::LIST: {
return args[0].get().getList().values.back();
const auto &items = args[0].get().getList().values;
return items.empty() ? Value::kNullValue : items.back();
}
default: {
return Value::kNullBadType;
Expand Down
12 changes: 12 additions & 0 deletions tests/tck/features/yield/return.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Feature: Return. A standalone return sentence is actually a yield sentence
Then the result should be, in any order:
| sum |
| 2 |
When executing query:
"""
RETURN last(LIST[]) AS a, head(LIST[]) AS b
"""
Then the result should be, in any order:
| a | b |
| NULL | NULL |
When executing query:
"""
RETURN 1- -1 AS sub
Expand All @@ -26,6 +33,11 @@ Feature: Return. A standalone return sentence is actually a yield sentence
RETURN 1--1 AS sub
"""
Then a SyntaxError should be raised at runtime: syntax error near `--'
When executing query:
"""
MATCH (v:player) RETURN none_direct_dst(LIST[]) AS a
"""
Then a SemanticError should be raised at runtime: Type error `none_direct_dst([])'
When executing query:
"""
RETURN [2,3 ] - [3] AS sub
Expand Down

0 comments on commit 0f6aa08

Please sign in to comment.