From 20eb9c8dae8a33a951e3e9d20cff6059787f7317 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Thu, 11 May 2023 12:20:00 -0700 Subject: [PATCH] Avoid crashing if there is a polygon ring containing only one point (#102) --- CHANGELOG.md | 4 ++++ geometry.cpp | 10 ++++++++++ version.hpp | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77cd52cb..1c4b175b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.26.1 + +* Avoid crashing if there is a polygon ring with only one point + # 2.26.0 * Fix bugs in --no-simplification-of-shared-nodes diff --git a/geometry.cpp b/geometry.cpp index 428d6ed8..da48c488 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -1049,6 +1049,16 @@ drawvec fix_polygon(drawvec &geom) { } } + // A polygon ring must contain at least three points + // (and really should contain four). If this one does + // not have enough, avoid a division by zero trying to + // calculate the centroid below. + if (j - i < 3) { + i = j - 1; + outer = 0; + continue; + } + // Make a temporary copy of the ring. // Close it if it isn't closed. diff --git a/version.hpp b/version.hpp index 3756d66e..551372a4 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "v2.26.0" +#define VERSION "v2.26.1" #endif