7676
7777# Set ordinate values in a Coordinate Sequence (Return 0 on exception)
7878function setX! (ptr:: GEOSCoordSeq , i:: Integer , value:: Real , context:: GEOSContext = _context)
79+ if ! (0 < i <= getSize (ptr, context))
80+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
81+ end
7982 result = GEOSCoordSeq_setX_r (context. ptr, ptr, i - 1 , value)
8083 if result == 0
8184 error (" LibGEOS: Error in GEOSCoordSeq_setX" )
@@ -84,6 +87,9 @@ function setX!(ptr::GEOSCoordSeq, i::Integer, value::Real, context::GEOSContext
8487end
8588
8689function setY! (ptr:: GEOSCoordSeq , i:: Integer , value:: Real , context:: GEOSContext = _context)
90+ if ! (0 < i <= getSize (ptr, context))
91+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
92+ end
8793 result = GEOSCoordSeq_setY_r (context. ptr, ptr, i - 1 , value)
8894 if result == 0
8995 error (" LibGEOS: Error in GEOSCoordSeq_setY" )
@@ -92,6 +98,9 @@ function setY!(ptr::GEOSCoordSeq, i::Integer, value::Real, context::GEOSContext
9298end
9399
94100function setZ! (ptr:: GEOSCoordSeq , i:: Integer , value:: Real , context:: GEOSContext = _context)
101+ if ! (0 < i <= getSize (ptr, context))
102+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
103+ end
95104 result = GEOSCoordSeq_setZ_r (context. ptr, ptr, i - 1 , value)
96105 if result == 0
97106 error (" LibGEOS: Error in GEOSCoordSeq_setZ" )
@@ -128,6 +137,9 @@ function setCoordSeq!(
128137)
129138 ndim = length (coords)
130139 @assert ndim >= 2
140+ if ! (0 < i <= getSize (ptr, context))
141+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
142+ end
131143 setX! (ptr, i, coords[1 ], context)
132144 setY! (ptr, i, coords[2 ], context)
133145 ndim >= 3 && setZ! (ptr, i, coords[3 ], context)
@@ -188,6 +200,9 @@ function createCoordSeq(coords::Vector{Vector{Float64}}, context::GEOSContext =
188200end
189201
190202function getX (ptr:: GEOSCoordSeq , i:: Integer , context:: GEOSContext = _context)
203+ if ! (0 < i <= getSize (ptr, context))
204+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
205+ end
191206 out = Ref {Float64} ()
192207 result = GEOSCoordSeq_getX_r (context. ptr, ptr, i - 1 , out)
193208 if result == 0
@@ -208,6 +223,9 @@ function getX(ptr::GEOSCoordSeq, context::GEOSContext = _context)
208223end
209224
210225function getY (ptr:: GEOSCoordSeq , i:: Integer , context:: GEOSContext = _context)
226+ if ! (0 < i <= getSize (ptr, context))
227+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
228+ end
211229 out = Ref {Float64} ()
212230 result = GEOSCoordSeq_getY_r (context. ptr, ptr, i - 1 , out)
213231 if result == 0
@@ -228,6 +246,9 @@ function getY(ptr::GEOSCoordSeq, context::GEOSContext = _context)
228246end
229247
230248function getZ (ptr:: GEOSCoordSeq , i:: Integer , context:: GEOSContext = _context)
249+ if ! (0 < i <= getSize (ptr, context))
250+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
251+ end
231252 out = Ref {Float64} ()
232253 result = GEOSCoordSeq_getZ_r (context. ptr, ptr, i - 1 , out)
233254 if result == 0
@@ -248,6 +269,9 @@ function getZ(ptr::GEOSCoordSeq, context::GEOSContext = _context)
248269end
249270
250271function getCoordinates (ptr:: GEOSCoordSeq , i:: Integer , context:: GEOSContext = _context)
272+ if ! (0 < i <= getSize (ptr, context))
273+ error (" LibGEOS: i=$i is out of bounds for CoordSeq with size=$(getSize (ptr, context)) " )
274+ end
251275 ndim = getDimensions (ptr, context)
252276 coord = Array {Float64} (undef, ndim)
253277 start = pointer (coord)
@@ -1240,6 +1264,9 @@ end
12401264
12411265# Call only on LINESTRING, and must be freed by caller (Returns NULL on exception)
12421266function getPoint (ptr:: GEOSGeom , n:: Integer , context:: GEOSContext = _context)
1267+ if ! (0 < n <= numPoints (ptr, context))
1268+ error (" LibGEOS: n=$n is out of bounds for LineString with numPoints=$(numPoints (ptr, context)) " )
1269+ end
12431270 result = GEOSGeomGetPointN_r (context. ptr, ptr, n - 1 )
12441271 if result == C_NULL
12451272 error (" LibGEOS: Error in GEOSGeomGetPointN" )
0 commit comments