[postgis-tickets] r15956 - Undefined behaviour in pointarray_to_encoded_polyline

Paul Ramsey pramsey at cleverelephant.ca
Tue Oct 10 11:05:11 PDT 2017


Author: pramsey
Date: 2017-10-10 11:05:11 -0700 (Tue, 10 Oct 2017)
New Revision: 15956

Modified:
   trunk/liblwgeom/lwout_encoded_polyline.c
Log:
Undefined behaviour in pointarray_to_encoded_polyline 
(Closes #3891)



Modified: trunk/liblwgeom/lwout_encoded_polyline.c
===================================================================
--- trunk/liblwgeom/lwout_encoded_polyline.c	2017-10-10 18:04:56 UTC (rev 15955)
+++ trunk/liblwgeom/lwout_encoded_polyline.c	2017-10-10 18:05:11 UTC (rev 15956)
@@ -73,7 +73,7 @@
 	stringbuffer_t *sb;
 	double scale = pow(10,precision);
 
-	/* Take the double value and multiply it by 1x10^percision, rounding the result */
+	/* Take the double value and multiply it by 1x10^precision, rounding the result */
 	prevPoint = getPoint2d_cp(pa, 0);
 	delta[0] = round(prevPoint->y*scale);
 	delta[1] = round(prevPoint->x*scale);
@@ -90,8 +90,8 @@
 	/* value to binary: a negative value must be calculated using its two's complement */
 	for (i=0; i<pa->npoints*2; i++)
 	{
-		/* Left-shift the binary value one bit */
-		delta[i] <<= 1;
+		/* Multiply by 2 for a signed left shift */
+		delta[i] *= 2;
 		/* if value is negative, invert this encoding */
 		if (delta[i] < 0) {
 			delta[i] = ~(delta[i]);



More information about the postgis-tickets mailing list