From f7e954ad1cf99a65b1785d999058898a6d56e014 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 5 Jun 2019 15:01:14 +0900 Subject: [PATCH] Rework code using list_delete_cell() in MergeAttributes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When merging two attributes, we are sure that at least one remains. However, when deleting one element in the attribute list we may finish with an empty list returned as NIL by list_delete_cell(), but the code failed to track that, which is not project-like. Adjust the call so as we check for an empty list, and make use of it in an assertion. This has been introduced by e7b3349, when adding support for CREATE TABLE OF. Author: Mark Dilger Reviewed-by: Álvaro Herrera, Michael Paquier Discussion: https://postgr.es/m/CAE-h2TpPDqSWgOvfvSziOaMngMPwW+QZcmPpY8hQ_KOJ2+3hXQ@mail.gmail.com --- src/backend/commands/tablecmds.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 95af5ec2dc..e13b96d252 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2088,7 +2088,13 @@ MergeAttributes(List *schema, List *supers, char relpersistence, coldef->cooked_default = restdef->cooked_default; coldef->constraints = restdef->constraints; coldef->is_from_type = false; - list_delete_cell(schema, rest, prev); + schema = list_delete_cell(schema, rest, prev); + + /* + * As two elements are merged and one is removed, we + * should never finish with an empty list. + */ + Assert(schema != NIL); } else ereport(ERROR, -- 2.40.0