Commit a8cbd5f1 authored by Raúl Marín's avatar Raúl Marín

Avoid undefined behaviour in next_float functions (Raúl Marín)

Closes #4247
Closes https://github.com/postgis/postgis/pull/339



git-svn-id: http://svn.osgeo.org/postgis/trunk@17038 b70326c6-7e19-0410-871a-916f4a2858ee
parent 8b5e2b01
Pipeline #37388117 passed with stage
in 29 minutes and 39 seconds
......@@ -39,6 +39,7 @@ PostGIS 3.0.0
- #4326, Allocate enough memory in gidx_to_string (Raúl Marín)
- #4190, Avoid undefined behaviour in gserialized_estimate (Raúl Marín)
- #4233, Fix undefined behaviour in gserialized_spgist_picksplit_nd (Raúl Marín)
- #4247, Avoid undefined behaviour in next_float functions (Raúl Marín)
PostGIS 2.5.0
2018/09/23
......
......@@ -688,6 +688,26 @@ static void test_f2d(void)
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);
}
/*
......
......@@ -50,7 +50,12 @@ lwgeom_version()
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;
......@@ -66,7 +71,12 @@ next_float_down(double d)
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment