[Patch] Fix bounds check in trim_array()

Martin Kalcher <martin.kalcher@aboutsource.net>

From: Martin Kalcher <martin.kalcher@aboutsource.net>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-25T14:40:51Z
Lists: pgsql-hackers

Attachments

Hi,

while working on something else i encountered a bug in the trim_array() 
function. The bounds check fails for empty arrays without any 
dimensions. It reads the size of the non existing first dimension to 
determine the arrays length.

   select trim_array('{}'::int[], 10);
   ------------
    {}

   select trim_array('{}'::int[], 100);
   ERROR:  number of elements to trim must be between 0 and 64

The attached patch fixes that check.

Martin

Commits

  1. Fix trim_array() for zero-dimensional array argument.