[postgis-tickets] r16638 - Clean memory sanitizer warnings

Raul raul at rmr.ninja
Fri Jul 6 07:49:33 PDT 2018


Author: algunenano
Date: 2018-07-06 07:49:32 -0700 (Fri, 06 Jul 2018)
New Revision: 16638

Modified:
   trunk/liblwgeom/lwgeom_geos.c
   trunk/liblwgeom/lwgeom_geos_clean.c
   trunk/liblwgeom/lwprint.c
   trunk/liblwgeom/lwspheroid.c
Log:
Clean memory sanitizer warnings

References #4118
Closes https://github.com/postgis/postgis/pull/265



Modified: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c	2018-07-06 13:14:06 UTC (rev 16637)
+++ trunk/liblwgeom/lwgeom_geos.c	2018-07-06 14:49:32 UTC (rev 16638)
@@ -62,9 +62,9 @@
 ptarray_from_GEOSCoordSeq(const GEOSCoordSequence* cs, uint8_t want3d)
 {
 	uint32_t dims = 2;
-	uint32_t size, i;
+	uint32_t size = 0, i;
 	POINTARRAY* pa;
-	POINT4D point;
+	POINT4D point = { 0.0, 0.0, 0.0, 0.0 };
 
 	LWDEBUG(2, "ptarray_fromGEOSCoordSeq called");
 
@@ -377,7 +377,7 @@
 			shell = ptarray_to_GEOSLinearRing(lwpoly->rings[0], autofix);
 			if (!shell) return NULL;
 			ngeoms = lwpoly->nrings - 1;
-			if (ngeoms > 0) geoms = malloc(sizeof(GEOSGeom) * ngeoms);
+			if (ngeoms > 0) geoms = lwalloc(sizeof(GEOSGeom) * ngeoms);
 
 			for (i = 1; i < lwpoly->nrings; i++)
 			{
@@ -387,13 +387,13 @@
 					uint32_t k;
 					for (k = 0; k < i - 1; k++)
 						GEOSGeom_destroy(geoms[k]);
-					free(geoms);
+					lwfree(geoms);
 					GEOSGeom_destroy(shell);
 					return NULL;
 				}
 			}
 			g = GEOSGeom_createPolygon(shell, geoms, ngeoms);
-			if (geoms) free(geoms);
+			if (geoms) lwfree(geoms);
 		}
 		if (!g) return NULL;
 		break;
@@ -413,7 +413,7 @@
 		lwc = (LWCOLLECTION*)lwgeom;
 
 		ngeoms = lwc->ngeoms;
-		if (ngeoms > 0) geoms = malloc(sizeof(GEOSGeom) * ngeoms);
+		if (ngeoms > 0) geoms = lwalloc(sizeof(GEOSGeom) * ngeoms);
 
 		j = 0;
 		for (i = 0; i < ngeoms; ++i)
@@ -428,13 +428,13 @@
 				uint32_t k;
 				for (k = 0; k < j; k++)
 					GEOSGeom_destroy(geoms[k]);
-				free(geoms);
+				lwfree(geoms);
 				return NULL;
 			}
 			geoms[j++] = g;
 		}
 		g = GEOSGeom_createCollection(geostype, geoms, j);
-		if (ngeoms > 0) free(geoms);
+		if (ngeoms > 0) lwfree(geoms);
 		if (!g) return NULL;
 		break;
 

Modified: trunk/liblwgeom/lwgeom_geos_clean.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos_clean.c	2018-07-06 13:14:06 UTC (rev 16637)
+++ trunk/liblwgeom/lwgeom_geos_clean.c	2018-07-06 14:49:32 UTC (rev 16638)
@@ -43,11 +43,11 @@
 GEOSGeometry*
 LWGEOM_GEOS_getPointN(const GEOSGeometry* g_in, uint32_t n)
 {
-	uint32_t dims;
+	uint32_t dims = 0;
 	const GEOSCoordSequence* seq_in;
 	GEOSCoordSeq seq_out;
 	double val;
-	uint32_t sz;
+	uint32_t sz = 0;
 	int gn;
 	GEOSGeometry* ret;
 

Modified: trunk/liblwgeom/lwprint.c
===================================================================
--- trunk/liblwgeom/lwprint.c	2018-07-06 13:14:06 UTC (rev 16637)
+++ trunk/liblwgeom/lwprint.c	2018-07-06 14:49:32 UTC (rev 16638)
@@ -378,6 +378,8 @@
 
 	/* Allocate space for the result.  Leave plenty of room for excess digits, negative sign, etc.*/
 	result = (char*)lwalloc(format_length + WORK_SIZE);
+	memset(result, 0, format_length + WORK_SIZE);
+
 	/* Append all the pieces together. There may be less than 9, but in that case the rest will be blank. */
 	strcpy(result, pieces[0]);
 	for (index = 1; index < NUM_PIECES; index++)

Modified: trunk/liblwgeom/lwspheroid.c
===================================================================
--- trunk/liblwgeom/lwspheroid.c	2018-07-06 13:14:06 UTC (rev 16637)
+++ trunk/liblwgeom/lwspheroid.c	2018-07-06 14:49:32 UTC (rev 16638)
@@ -84,7 +84,7 @@
 	double lon1 = a->lon * 180.0 / M_PI;
 	double lat2 = b->lat * 180.0 / M_PI;
 	double lon2 = b->lon * 180.0 / M_PI;
-	double s12; /* return distance */
+	double s12 = 0.0; /* return distance */
 	geod_inverse(&gd, lat1, lon1, lat2, lon2, &s12, 0, 0);
 	return s12;
 }



More information about the postgis-tickets mailing list