Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e35ded2

Browse files
committed
Fix list_copy_head() with empty Lists
list_copy_head() given an empty List would crash from trying to dereference the List to obtain its length. Since NIL is how we represent an empty List, we should just be returning another empty List in this case. list_copy_head() is new to v16, so let's fix it now before too many people start coding around the buggy NIL behavior. Reported-by: Miroslav Bendik Discussion: https://postgr.es/m/CAPoEpV02WhawuWnmnKet6BqU63bEu7oec0pJc=nKMtPsHMzTXQ@mail.gmail.com
1 parent 2584639 commit e35ded2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/backend/nodes/list.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,11 +1593,11 @@ list_copy_head(const List *oldlist, int len)
15931593
{
15941594
List *newlist;
15951595

1596-
len = Min(oldlist->length, len);
1597-
1598-
if (len <= 0)
1596+
if (oldlist == NIL || len <= 0)
15991597
return NIL;
16001598

1599+
len = Min(oldlist->length, len);
1600+
16011601
newlist = new_list(oldlist->type, len);
16021602
memcpy(newlist->elements, oldlist->elements, len * sizeof(ListCell));
16031603

0 commit comments

Comments
 (0)