Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash of list related functions #5383

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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