[geos-commits] r2697 - trunk/source/linearref

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Oct 23 06:13:13 EDT 2009


Author: strk
Date: 2009-10-23 06:13:12 -0400 (Fri, 23 Oct 2009)
New Revision: 2697

Modified:
   trunk/source/linearref/LinearGeometryBuilder.cpp
Log:
Fix memory access error (#283)


Modified: trunk/source/linearref/LinearGeometryBuilder.cpp
===================================================================
--- trunk/source/linearref/LinearGeometryBuilder.cpp	2009-10-23 10:03:22 UTC (rev 2696)
+++ trunk/source/linearref/LinearGeometryBuilder.cpp	2009-10-23 10:13:12 UTC (rev 2697)
@@ -29,6 +29,8 @@
 #include <geos/linearref/LinearGeometryBuilder.h>
 #include <geos/util/IllegalArgumentException.h>
 
+#include <cassert>
+
 using namespace std;
 
 using namespace geos::geom;
@@ -105,7 +107,17 @@
 		}
 		else if (fixInvalidLines)
 		{
-			add((*coordList)[0]);
+			assert(!coordList->isEmpty()); // just to be sure
+
+			// NOTE: we copy the point cause reallocation of
+			//       vector memory will invalidate the reference
+			//       to one of its elements.
+			//
+			//       We wouldn't have such problems with a vector
+			//       of pointers (as used in JTS)...
+			//
+			Coordinate firstPoint = (*coordList)[0];
+			add(firstPoint);
 		}
 	}
 



More information about the geos-commits mailing list