]> granicus.if.org Git - postgis/commitdiff
Undefined behaviour in pointarray_to_encoded_polyline
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 10 Oct 2017 18:05:11 +0000 (18:05 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 10 Oct 2017 18:05:11 +0000 (18:05 +0000)
(Closes #3891)

git-svn-id: http://svn.osgeo.org/postgis/trunk@15956 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwout_encoded_polyline.c

index 8b1e617c77df404183ee3fb1805e676e762430de..050b4587c3fbc6fb435006d512b0c100b16ba227 100644 (file)
@@ -73,7 +73,7 @@ char * pointarray_to_encoded_polyline(const POINTARRAY *pa, int precision)
        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 @@ char * pointarray_to_encoded_polyline(const POINTARRAY *pa, int precision)
        /* 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]);