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

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

NEWS
liblwgeom/lwout_encoded_polyline.c

diff --git a/NEWS b/NEWS
index ca710c727502535fc0efdf8a9d8a4d25419727ba..0e930c2b6c49e4474fc26bd0b1b17d1dc11da430 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ YYYY/MM/DD
   - #3864, Performance improvements for b-tree geometry sorts
   - #3874, lw_dist2d_pt_arc division by zero
   - #3882, undefined behaviour in zigzag with negative inputs
+  - #3891, undefined behaviour in pointarray_to_encoded_polyline
 
 
 PostGIS 2.4.0
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]);