aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/nodes/list.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index 75aa5baa807..90f93e893cf 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -1553,11 +1553,11 @@ list_copy_head(const List *oldlist, int len)
{
List *newlist;
- len = Min(oldlist->length, len);
-
- if (len <= 0)
+ if (oldlist == NIL || len <= 0)
return NIL;
+ len = Min(oldlist->length, len);
+
newlist = new_list(oldlist->type, len);
memcpy(newlist->elements, oldlist->elements, len * sizeof(ListCell));