From 1df1ca6b32aa1842959aaa2b853701c6f06d922d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Harrtell?= Date: Tue, 25 Apr 2017 21:39:58 +0000 Subject: [PATCH] Cast smaller integer types to the destination type Fixes #3741 and #3742 git-svn-id: http://svn.osgeo.org/postgis/trunk@15372 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/mvt.c | 6 ++++-- regress/mvt.sql | 23 +++++++++-------------- regress/mvt_expected | 2 ++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/postgis/mvt.c b/postgis/mvt.c index d956e1d9b..f2a20cfb7 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -368,11 +368,13 @@ static void encode_values(struct mvt_agg_context *ctx) { \ type value = datumfunc(datum); \ if (value >= 0) { \ - MVT_PARSE_VALUE(value, mvt_kv_uint_value, \ + uint64_t cvalue = value; \ + MVT_PARSE_VALUE(cvalue, mvt_kv_uint_value, \ uint_values_hash, uint_value, \ sizeof(uint64_t)) \ } else { \ - MVT_PARSE_VALUE(value, mvt_kv_sint_value, \ + int64_t cvalue = value; \ + MVT_PARSE_VALUE(cvalue, mvt_kv_sint_value, \ sint_values_hash, sint_value, \ sizeof(int64_t)) \ } \ diff --git a/regress/mvt.sql b/regress/mvt.sql index ff81f46a3..68b156d66 100644 --- a/regress/mvt.sql +++ b/regress/mvt.sql @@ -96,20 +96,15 @@ SELECT 'TA7', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( UNION SELECT 'othertest' AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q; --- TA8 results in incorrect encoding (redundant values) except in debug builds with specific logging --- Memory allocation issues are suspected ---SELECT 'TA8', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( --- SELECT 1 AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), --- ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom --- UNION --- SELECT 1 AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), --- ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom --- UNION --- SELECT 2 AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), --- ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q; --- Expected output: --- TA8|GkEKBHRlc3QSDBICAAAYASIECTLePxIMEgIAABgBIgQJNNw/EgwSAgABGAEiBAk03D8aAmMxIgIo --- ASICKAIogCB4Ag== +SELECT 'TA8', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( + SELECT 1::int AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom + UNION + SELECT 1::int AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom + UNION + SELECT 2::int AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q; -- unsupported input SELECT 'TU2'; diff --git a/regress/mvt_expected b/regress/mvt_expected index eb149db60..b90af1bdb 100644 --- a/regress/mvt_expected +++ b/regress/mvt_expected @@ -25,6 +25,8 @@ TA5|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag== TA6|GisKBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgIwASiAIHgC TA7|Gk4KBHRlc3QSDBICAAAYASIECTTcPxIMEgIAARgBIgQJMt4/EgwSAgABGAEiBAk03D8aAmMxIgsK CW90aGVydGVzdCIGCgR0ZXN0KIAgeAI= +TA8|GkEKBHRlc3QSDBICAAAYASIECTLePxIMEgIAABgBIgQJNNw/EgwSAgABGAEiBAk03D8aAmMxIgIo +ASICKAIogCB4Ag== TU2 ERROR: pgis_asmvt_transfn: parameter row cannot be other than a rowtype TU3 -- 2.40.0