pgsql: Fix crash in contrib/ltree's lca() function for empty input arra

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix crash in contrib/ltree's lca() function for empty input arra
Date: 2018-07-13 22:45:48
Message-ID: E1fe6ou-0001wQ-20@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix crash in contrib/ltree's lca() function for empty input array.

lca_inner() wasn't prepared for the possibility of getting no inputs.
Fix that, and make some cosmetic improvements to the code while at it.

Also, I thought the documentation of this function as returning the
"longest common prefix" of the paths was entirely misleading; it really
returns a path one shorter than the longest common prefix, for the typical
definition of "prefix". Don't use that term in the docs, and adjust the
examples to clarify what really happens.

This has been broken since its beginning, so back-patch to all supported
branches.

Per report from Hailong Li. Thanks to Pierre Ducroquet for diagnosing
and for the initial patch, though I whacked it around some and added
test cases.

Discussion: https://postgr.es/m/5b0d8e4f-f2a3-1305-d612-e00e35a7be66@qunar.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dbd7f4e7c433b4fc202e9520d2bd360200f07805

Modified Files
--------------
contrib/ltree/expected/ltree.out | 18 ++++++++++++++++++
contrib/ltree/ltree_op.c | 34 +++++++++++++++++++++++++---------
contrib/ltree/sql/ltree.sql | 3 +++
doc/src/sgml/ltree.sgml | 8 ++++----
4 files changed, 50 insertions(+), 13 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2018-07-14 12:18:50 Re: pgsql: Fix FK checks of TRUNCATE involving partitioned tables
Previous Message Robert Haas 2018-07-13 21:57:59 Re: pgsql: Add wait event for fsync of WAL segments