Opened 3 years ago

Closed 3 years ago

#4953 closed defect (fixed)

Small fix to function edge_distance_to_point

Reported by: ezimanyi Owned by: pramsey
Priority: medium Milestone: PostGIS 3.1.3
Component: postgis Version: 2.5.x -- EOL
Keywords: geodetic Cc:

Description

The third parameter closest can be NULL. This is tested at the end of the function but not at the beginning. The code below is extracted from PostGIS 3.1.2.

double edge_distance_to_point(const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *gp, GEOGRAPHIC_POINT *closest)
{
  double d1 = 1000000000.0, d2, d3, d_nearest;
  POINT3D n, p, k;
  GEOGRAPHIC_POINT gk, g_nearest;

  /* Zero length edge, */
  if ( geographic_point_equals(&(e->start), &(e->end)) )
  {
    if (closest) <----------------- Missing test
      *closest = e->start;
    return sphere_distance(&(e->start), gp);
  }

  [...]

  if (closest)
    *closest = g_nearest;

  return d_nearest;
}

Regards

Esteban

Change History (1)

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

Resolution: fixed
Status: newclosed

In d3f1c2b5/git:

Add guard to return pointer, closes #4953

Note: See TracTickets for help on using tickets.