[postgis-tickets] r16587 - Avoid segfault in median test (32bits)
Raul
raul at rmr.ninja
Wed May 23 02:27:31 PDT 2018
Author: algunenano
Date: 2018-05-23 02:27:31 -0700 (Wed, 23 May 2018)
New Revision: 16587
Modified:
branches/2.3/liblwgeom/lwgeom_median.c
Log:
Avoid segfault in median test (32bits)
References #4095
Modified: branches/2.3/liblwgeom/lwgeom_median.c
===================================================================
--- branches/2.3/liblwgeom/lwgeom_median.c 2018-05-22 19:38:12 UTC (rev 16586)
+++ branches/2.3/liblwgeom/lwgeom_median.c 2018-05-23 09:27:31 UTC (rev 16587)
@@ -86,6 +86,7 @@
double dy = 0;
double dz = 0;
double d_sqr;
+ double r_inv;
for (i = 0; i < npoints; i++)
{
@@ -98,15 +99,11 @@
}
d_sqr = sqrt (dx*dx + dy*dy + dz*dz);
+ r_inv = d_sqr > DBL_EPSILON ? 1.0 / d_sqr : 1.0;
- if (d_sqr > DBL_EPSILON)
- {
- double r_inv = 1.0 / d_sqr;
-
- next.x = FP_MAX(0, 1.0 - r_inv)*next.x + FP_MIN(1.0, r_inv)*curr->x;
- next.y = FP_MAX(0, 1.0 - r_inv)*next.y + FP_MIN(1.0, r_inv)*curr->y;
- next.z = FP_MAX(0, 1.0 - r_inv)*next.z + FP_MIN(1.0, r_inv)*curr->z;
- }
+ next.x = FP_MAX(0, 1.0 - r_inv)*next.x + FP_MIN(1.0, r_inv)*curr->x;
+ next.y = FP_MAX(0, 1.0 - r_inv)*next.y + FP_MIN(1.0, r_inv)*curr->y;
+ next.z = FP_MAX(0, 1.0 - r_inv)*next.z + FP_MIN(1.0, r_inv)*curr->z;
}
delta = distance3d_pt_pt(curr, &next);
More information about the postgis-tickets
mailing list