From fafb48a0d98a4d782ad0c77363e01ab266ea762a Mon Sep 17 00:00:00 2001 From: Dan Baston Date: Thu, 29 Dec 2022 19:23:44 -0500 Subject: [PATCH] NodingIntersectionFinder: Fix false-positive intersection (#780) The test for adjacent segments may give an incorrect result due to unsigned integer wraparound when segIndex0 > segIndex1. This apparently did not occur until d210a94fe. Fixes https://github.com/libgeos/geos/issues/770 --- src/noding/NodingIntersectionFinder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/noding/NodingIntersectionFinder.cpp b/src/noding/NodingIntersectionFinder.cpp index ab6eb857a5..ce08241cea 100644 --- a/src/noding/NodingIntersectionFinder.cpp +++ b/src/noding/NodingIntersectionFinder.cpp @@ -79,8 +79,8 @@ NodingIntersectionFinder::processIntersections( /** * Check for an intersection between two vertices which are not both endpoints. */ - long long segDiff = static_cast(segIndex1 - segIndex0); - bool isAdjacentSegment = isSameSegString && std::abs(segDiff) <= 1; + std::size_t segDiff = std::max(segIndex0, segIndex1) - std::min(segIndex0, segIndex1); + bool isAdjacentSegment = isSameSegString && segDiff <= 1; bool isInteriorVertexInt = (!isAdjacentSegment) && isInteriorVertexIntersection(p00, p01, p10, p11, isEnd00, isEnd01, isEnd10, isEnd11);