[postgis-tickets] r15914 - Undefined behaviour in TYPMOD_GET_SRID
Paul Ramsey
pramsey at cleverelephant.ca
Fri Oct 6 06:12:00 PDT 2017
Author: pramsey
Date: 2017-10-06 06:12:00 -0700 (Fri, 06 Oct 2017)
New Revision: 15914
Modified:
trunk/liblwgeom/cunit/cu_libgeom.c
trunk/liblwgeom/liblwgeom.h.in
Log:
Undefined behaviour in TYPMOD_GET_SRID
References #3880
Modified: trunk/liblwgeom/cunit/cu_libgeom.c
===================================================================
--- trunk/liblwgeom/cunit/cu_libgeom.c 2017-10-06 01:00:27 UTC (rev 15913)
+++ trunk/liblwgeom/cunit/cu_libgeom.c 2017-10-06 13:12:00 UTC (rev 15914)
@@ -35,6 +35,16 @@
rv = TYPMOD_GET_SRID(typmod);
CU_ASSERT_EQUAL(rv, srid);
+ srid = 999999;
+ TYPMOD_SET_SRID(typmod,srid);
+ rv = TYPMOD_GET_SRID(typmod);
+ CU_ASSERT_EQUAL(rv, srid);
+
+ srid = -999999;
+ TYPMOD_SET_SRID(typmod,srid);
+ rv = TYPMOD_GET_SRID(typmod);
+ CU_ASSERT_EQUAL(rv, srid);
+
srid = SRID_UNKNOWN;
TYPMOD_SET_SRID(typmod,srid);
rv = TYPMOD_GET_SRID(typmod);
Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in 2017-10-06 01:00:27 UTC (rev 15913)
+++ trunk/liblwgeom/liblwgeom.h.in 2017-10-06 13:12:00 UTC (rev 15914)
@@ -161,7 +161,7 @@
* ZM Flags = Bottom 2 bits.
*/
-#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x1FFFFF00)<<3)>>11)
+#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
#define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
#define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
#define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
More information about the postgis-tickets
mailing list