r17037 - Avoid undefined behaviour in next_float functions (Raúl Marín)
Raul
raul at rmr.ninja
Wed Nov 21 03:45:43 PST 2018
Author: algunenano
Date: 2018-11-21 03:45:43 -0800 (Wed, 21 Nov 2018)
New Revision: 17037
Modified:
branches/2.5/NEWS
branches/2.5/liblwgeom/cunit/cu_libgeom.c
branches/2.5/liblwgeom/lwgeom_api.c
Log:
Avoid undefined behaviour in next_float functions (Raúl Marín)
References #4247
Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS 2018-11-21 11:43:57 UTC (rev 17036)
+++ branches/2.5/NEWS 2018-11-21 11:45:43 UTC (rev 17037)
@@ -1,3 +1,9 @@
+PostGIS 2.5.2
+XXXX/XX/XX
+
+ * Bug fixes *
+ - #4247, Avoid undefined behaviour in next_float functions (Raúl Marín)
+
PostGIS 2.5.1
2018/11/18
@@ -19,7 +25,7 @@
- #4216, Revert non-sliced box access (Paul Ramsey)
- #2767, Documentation for AddRasterConstraint optional parameters (Sunveer Singh)
- #4326, Allocate enough memory in gidx_to_string (Raúl Marín)
- - #4190, Avoid undefined behaviour in gserialized_estimate
+ - #4190, Avoid undefined behaviour in gserialized_estimate (Raúl Marín)
PostGIS 2.5.0
Modified: branches/2.5/liblwgeom/cunit/cu_libgeom.c
===================================================================
--- branches/2.5/liblwgeom/cunit/cu_libgeom.c 2018-11-21 11:43:57 UTC (rev 17036)
+++ branches/2.5/liblwgeom/cunit/cu_libgeom.c 2018-11-21 11:45:43 UTC (rev 17037)
@@ -688,6 +688,26 @@
f = next_float_up(d);
d = next_float_up(f);
CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
+
+ d = DBL_MAX;
+ f = next_float_up(d);
+ d = next_float_up(f);
+ CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
+
+ d = DBL_MAX;
+ f = next_float_down(d);
+ d = next_float_down(f);
+ CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
+
+ d = -DBL_MAX;
+ f = next_float_up(d);
+ d = next_float_up(f);
+ CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
+
+ d = -DBL_MAX;
+ f = next_float_down(d);
+ d = next_float_down(f);
+ CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
}
/*
Modified: branches/2.5/liblwgeom/lwgeom_api.c
===================================================================
--- branches/2.5/liblwgeom/lwgeom_api.c 2018-11-21 11:43:57 UTC (rev 17036)
+++ branches/2.5/liblwgeom/lwgeom_api.c 2018-11-21 11:45:43 UTC (rev 17037)
@@ -51,7 +51,12 @@
inline float
next_float_down(double d)
{
- float result = d;
+ float result;
+ if (d > (double)FLT_MAX)
+ return FLT_MAX;
+ if (d <= (double)-FLT_MAX)
+ return -FLT_MAX;
+ result = d;
if ( ((double)result) <=d )
return result;
@@ -67,7 +72,12 @@
inline float
next_float_up(double d)
{
- float result = d;
+ float result;
+ if (d >= (double)FLT_MAX)
+ return FLT_MAX;
+ if (d < (double)-FLT_MAX)
+ return -FLT_MAX;
+ result = d;
if ( ((double)result) >=d )
return result;
More information about the postgis-tickets
mailing list