[postgis-tickets] r16365 - lwprint_double: Avoid undefined behaviour with infinity
Paul Ramsey
pramsey at cleverelephant.ca
Fri Jan 26 07:10:59 PST 2018
Author: pramsey
Date: 2018-01-26 07:10:58 -0800 (Fri, 26 Jan 2018)
New Revision: 16365
Modified:
trunk/liblwgeom/lwprint.c
Log:
lwprint_double: Avoid undefined behaviour with infinity
(Raúl Marín Rodríguez)
Closes #4005
Closes https://github.com/postgis/postgis/pull/200
Modified: trunk/liblwgeom/lwprint.c
===================================================================
--- trunk/liblwgeom/lwprint.c 2018-01-26 15:01:15 UTC (rev 16364)
+++ trunk/liblwgeom/lwprint.c 2018-01-26 15:10:58 UTC (rev 16365)
@@ -488,7 +488,7 @@
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 @@
}
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);
}
More information about the postgis-tickets
mailing list