[postgis-tickets] r15998 - Allocate enough space for all possible GBOX string outputs (Ra?\195?\186l Mar?\195?\173n Rodr?\195?\173guez)

Paul Ramsey pramsey at cleverelephant.ca
Tue Oct 17 09:54:52 PDT 2017


Author: pramsey
Date: 2017-10-17 09:54:52 -0700 (Tue, 17 Oct 2017)
New Revision: 15998

Modified:
   branches/2.3/NEWS
   branches/2.3/liblwgeom/cunit/cu_geodetic.c
   branches/2.3/liblwgeom/g_box.c
Log:
Allocate enough space for all possible GBOX string outputs (Ra?\195?\186l Mar?\195?\173n Rodr?\195?\173guez)
Closes #3907



Modified: branches/2.3/NEWS
===================================================================
--- branches/2.3/NEWS	2017-10-17 16:53:45 UTC (rev 15997)
+++ branches/2.3/NEWS	2017-10-17 16:54:52 UTC (rev 15998)
@@ -33,6 +33,7 @@
   - #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

Modified: branches/2.3/liblwgeom/cunit/cu_geodetic.c
===================================================================
--- branches/2.3/liblwgeom/cunit/cu_geodetic.c	2017-10-17 16:53:45 UTC (rev 15997)
+++ branches/2.3/liblwgeom/cunit/cu_geodetic.c	2017-10-17 16:54:52 UTC (rev 15998)
@@ -1569,6 +1569,28 @@
 	/* 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 @@
 	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);
 }

Modified: branches/2.3/liblwgeom/g_box.c
===================================================================
--- branches/2.3/liblwgeom/g_box.c	2017-10-17 16:53:45 UTC (rev 15997)
+++ branches/2.3/liblwgeom/g_box.c	2017-10-17 16:54:52 UTC (rev 15998)
@@ -403,7 +403,7 @@
 
 char* gbox_to_string(const GBOX *gbox)
 {
-	static int sz = 128;
+	static int sz = 138;
 	char *str = NULL;
 
 	if ( ! gbox )



More information about the postgis-tickets mailing list