Fix list_copy_head() with empty Lists

David Rowley <drowley@postgresql.org>

Commit: e35ded29566f679e52888a8d34468bb51bc78bed
Author: David Rowley <drowley@postgresql.org>
Date: 2023-04-19T22:34:46Z
Releases: 16.0
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

Files

PathChange+/−
src/backend/nodes/list.c modified +3 −3

Discussion