Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#5036 closed defect (fixed)

PostGIS 3.2.0: ST_StartPoint with empty geometries

Reported by: ezimanyi Owned by: pramsey
Priority: medium Milestone: PostGIS 3.2.1
Component: postgis Version: master
Keywords: Cc:

Description

While performing the regression tests for MobilityDB with the latest version PostGIS 3.2.0 we found out that maybe the function LWGEOM_startpoint_linestring should test whether the argument is empty. Although the function correctly outputs a NULL value for empty geometries, it throws an error message as follows

test=# select ST_StartPoint(geometry 'linestring empty');
NOTICE:  lwgeom_api.c [138] called with n=0 and npoints=0
 st_startpoint
---------------

(1 row)

It may be useful to test whether the input geometry is empty before calling lwgeom_from_gserialized as suggested below.

Datum LWGEOM_startpoint_linestring(PG_FUNCTION_ARGS)
{
  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
  /* BEGIN NEW TEST */
  if (gserialized_is_empty(geom))
  {
    PG_RETURN_NULL();
  }
  /* END NEW TEST */
  
  GSERIALIZED *ret;
  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
  LWGEOM *lwpoint = NULL;
  POINT4D pt;

  if (lwgeom_startpoint(lwgeom, &pt) == LW_FAILURE)
  {
    PG_RETURN_NULL();
  }
  [...]
}

Change History (4)

comment:1 by robe, 2 years ago

Milestone: PostGIS 3.1.5PostGIS 3.2.1
Version: 2.5.xmaster

This looks like a debug message left in, not an error one. I confirm I see it too.

comment:2 by Paul Ramsey <pramsey@…>, 2 years ago

Resolution: fixed
Status: newclosed

In a05bf507/git:

Test for empty before reading start point. Closes #5036

comment:3 by Paul Ramsey <pramsey@…>, 2 years ago

In 49ee0d4/git:

Test for empty before reading start point. Closes #5036

comment:4 by Paul Ramsey <pramsey@…>, 2 years ago

In 49ee0d4/git:

Test for empty before reading start point. Closes #5036

Note: See TracTickets for help on using tickets.