From 65c6644a97fb80d808b607fd50815ad4eadec3db Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 17 Oct 2017 16:54:52 +0000 Subject: [PATCH] =?utf8?q?Allocate=20enough=20space=20for=20all=20possible?= =?utf8?q?=20GBOX=20string=20outputs=20(Ra=C3=BAl=20Mar=C3=ADn=20Rodr?= =?utf8?q?=C3=ADguez)=20Closes=20#3907?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.osgeo.org/postgis/branches/2.3@15998 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + liblwgeom/cunit/cu_geodetic.c | 23 +++++++++++++++++++++++ liblwgeom/g_box.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index d9bd01add..7525b71a9 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,7 @@ PostGIS 2.3.4 - #3882, undefined behaviour in zigzag with negative inputs - #3891, undefined behaviour in pointarray_to_encoded_polyline - #3895, throw error on malformed WKB input + - #3907, Allocate enough space for all possible GBOX string outputs (Raúl Marín Rodríguez) PostGIS 2.3.3 diff --git a/liblwgeom/cunit/cu_geodetic.c b/liblwgeom/cunit/cu_geodetic.c index ae61d0e6b..a9e9a5605 100644 --- a/liblwgeom/cunit/cu_geodetic.c +++ b/liblwgeom/cunit/cu_geodetic.c @@ -1569,6 +1569,28 @@ static void test_lwgeom_area_sphere(void) /* end #3393 */ } +static void test_gbox_to_string_truncated(void) +{ + GBOX g = { + .flags = 0, + .xmin = -DBL_MAX, + .xmax = -DBL_MAX, + .ymin = -DBL_MAX, + .ymax = -DBL_MAX, + .zmin = -DBL_MAX, + .zmax = -DBL_MAX, + .mmin = -DBL_MAX, + .mmax = -DBL_MAX, + }; + FLAGS_SET_Z(g.flags, 1); + FLAGS_SET_M(g.flags, 1); + char *c = gbox_to_string(&g); + + ASSERT_STRING_EQUAL(c, "GBOX((-1.7976931e+308,-1.7976931e+308,-1.7976931e+308,-1.7976931e+308),(-1.7976931e+308,-1.7976931e+308,-1.7976931e+308,-1.7976931e+308))"); + + lwfree(c); +} + /* ** Used by test harness to register the tests in this file. */ @@ -1598,4 +1620,5 @@ void geodetic_suite_setup(void) PG_ADD_TEST(suite, test_lwgeom_segmentize_sphere); PG_ADD_TEST(suite, test_ptarray_contains_point_sphere); PG_ADD_TEST(suite, test_ptarray_contains_point_sphere_iowa); + PG_ADD_TEST(suite, test_gbox_to_string_truncated); } diff --git a/liblwgeom/g_box.c b/liblwgeom/g_box.c index 4b8ba846d..dd3194855 100644 --- a/liblwgeom/g_box.c +++ b/liblwgeom/g_box.c @@ -403,7 +403,7 @@ GBOX* gbox_from_string(const char *str) char* gbox_to_string(const GBOX *gbox) { - static int sz = 128; + static int sz = 138; char *str = NULL; if ( ! gbox ) -- 2.49.0