diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 2706576b47c..a41cb5b980a 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -133,16 +133,19 @@ bool read_multi_point_WKT(std::istream& in, MultiPoint& mp) { std::string line; + bool found = false; while(internal::get_a_new_line(in, line)) { if(line.substr(0, 10).compare("MULTIPOINT") == 0) { CGAL::internal::Geometry_container gc(mp); - internal::read_wkt_or_fail_stream(in, line, gc); + found = internal::read_wkt_or_fail_stream(in, line, gc); break; } } - + if(! found){ + return false; + } return !in.fail(); } @@ -168,16 +171,20 @@ bool read_linestring_WKT(std::istream& in, LineString& polyline) { std::string line; + bool found = false; while(internal::get_a_new_line(in, line)) { if(line.substr(0, 10).compare("LINESTRING") == 0) { CGAL::internal::Geometry_container gc(polyline); - internal::read_wkt_or_fail_stream(in, line, gc); + found = internal::read_wkt_or_fail_stream(in, line, gc); break; } } + if(! found){ + return false; + } return !in.fail(); } @@ -199,6 +206,7 @@ bool read_multi_linestring_WKT(std::istream& in, MultiLineString& mls) { std::string line; + bool found = false; while(internal::get_a_new_line(in, line)) { if(line.substr(0, 15).compare("MULTILINESTRING") == 0) @@ -209,7 +217,7 @@ bool read_multi_linestring_WKT(std::istream& in, std::vector pr_range; CGAL::internal::Geometry_container, boost::geometry::multi_linestring_tag> gc(pr_range); - internal::read_wkt_or_fail_stream(in, line, gc); + found = internal::read_wkt_or_fail_stream(in, line, gc); for(LineString& ls : gc) { mls.push_back(*ls.range); } @@ -237,15 +245,19 @@ bool read_polygon_WKT(std::istream& in, Polygon& polygon) { std::string line; + bool found = false; while(internal::get_a_new_line(in, line)) { if(line.substr(0, 7).compare("POLYGON") == 0) { - internal::read_wkt_or_fail_stream(in, line, polygon); + found = internal::read_wkt_or_fail_stream(in, line, polygon); internal::pop_back_if_equal_to_front(polygon); break; } } + if(! found){ + return false; + } return !in.fail(); } @@ -268,12 +280,13 @@ bool read_multi_polygon_WKT(std::istream& in, MultiPolygon& polygons) { std::string line; + bool found = false; while(internal::get_a_new_line(in, line)) { if(line.substr(0, 12).compare("MULTIPOLYGON") == 0) { CGAL::internal::Geometry_container gc(polygons); - internal::read_wkt_or_fail_stream(in, line, gc); + found = internal::read_wkt_or_fail_stream(in, line, gc); for(auto& p : gc) internal::pop_back_if_equal_to_front(p); @@ -281,7 +294,9 @@ bool read_multi_polygon_WKT(std::istream& in, break; } } - + if(! found){ + return false; + } return !in.fail(); } diff --git a/Stream_support/test/Stream_support/test_WKT.cpp b/Stream_support/test/Stream_support/test_WKT.cpp index 7af1e011668..986bf421adc 100644 --- a/Stream_support/test/Stream_support/test_WKT.cpp +++ b/Stream_support/test/Stream_support/test_WKT.cpp @@ -24,6 +24,17 @@ typedef std::vector MultiPoint typedef std::vector MultiLinestring3; //////////////////////////////////////////////////////////////////////////////////////////////////// +bool test_mismatch() +{ + Point3 p(1,2,3); + MultiPoint3 mq; + std::stringstream ss; + CGAL::IO::write_point_WKT(ss, p); + bool b = CGAL::IO::read_multi_point_WKT(ss, mq); + assert(!b); + return !b; +} + bool test_WKT_3D() { { @@ -337,6 +348,8 @@ int main() assert(ok); ok = test_WKT_3D(); assert(ok); + ok = test_mismatch(); + assert(ok); return EXIT_SUCCESS; }