Skip to content

Commit

Permalink
Return 2D empty linestring on GEOSGeom_createLineString(NULL) (#998)
Browse files Browse the repository at this point in the history
References GH-993
  • Loading branch information
pramsey authored Nov 21, 2023
1 parent cbfa2ec commit 301bc46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/geom/GeometryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ std::unique_ptr<LineString>
GeometryFactory::createLineString(CoordinateSequence::Ptr && newCoords)
const
{
if (!newCoords)
return createLineString();
// Can't use make_unique with protected constructor
return std::unique_ptr<LineString>(new LineString(std::move(newCoords), *this));
}
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/capi/GEOSGeom_createTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
#include <cstdlib>
#include <memory>

#include "capi_test_utils.h"

namespace tut {
//
// Test Group
//

// Common data used in test cases.
struct test_capigeosgeom_create_data {
struct test_capigeosgeom_create_data : public capitest::utility
{
GEOSGeometry* geom1_;
GEOSContextHandle_t handle_;

Expand Down Expand Up @@ -177,6 +180,14 @@ void object::test<7>
geom1_ = nullptr;
}

template<>
template<>
void object::test<8>()
{
input_ = GEOSGeom_createLineString(NULL);
ensure_equals(GEOSHasZ(input_), 0);
ensure_equals(GEOSHasM(input_), 0);
}

} // namespace tut

1 change: 1 addition & 0 deletions tests/unit/capi/GEOSHasZMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ void object::test<9>()
ensure_equals(GEOSHasM(input_), 1);
}


} // namespace tut

0 comments on commit 301bc46

Please sign in to comment.