Commit a74efb32 authored by Paul Ramsey's avatar Paul Ramsey

lwprint_double: Avoid undefined behaviour with infinity

(Raúl Marín Rodríguez)
Closes #4005
Closes https://github.com/postgis/postgis/pull/200


git-svn-id: http://svn.osgeo.org/postgis/trunk@16365 b70326c6-7e19-0410-871a-916f4a2858ee
parent 5430d551
Pipeline #16679623 passed with stage
in 18 minutes and 19 seconds
......@@ -488,7 +488,7 @@ int
lwprint_double(double d, int maxdd, char* buf, size_t bufsize)
{
double ad = fabs(d);
int ndd = ad < 1 ? 0 : floor(log10(ad)) + 1; /* non-decimal digits */
int ndd;
int length = 0;
if (ad <= FP_TOLERANCE)
{
......@@ -497,6 +497,7 @@ lwprint_double(double d, int maxdd, char* buf, size_t bufsize)
}
if (ad < OUT_MAX_DOUBLE)
{
ndd = ad < 1 ? 0 : floor(log10(ad)) + 1; /* non-decimal digits */
if (maxdd > (OUT_MAX_DOUBLE_PRECISION - ndd)) maxdd -= ndd;
length = snprintf(buf, bufsize, "%.*f", maxdd, d);
}
......
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