From 0dad504e9185622d3d8e2bd90defedfd7aae56e9 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 8 Dec 2021 15:57:22 +0100 Subject: [PATCH] POLY_GRID_PARTITION: detect a divide by 0, set a wxASSERT and avoid the crash. --- libs/kimath/src/geometry/poly_grid_partition.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/kimath/src/geometry/poly_grid_partition.cpp b/libs/kimath/src/geometry/poly_grid_partition.cpp index b0adf4f781..62a8f0ac57 100644 --- a/libs/kimath/src/geometry/poly_grid_partition.cpp +++ b/libs/kimath/src/geometry/poly_grid_partition.cpp @@ -151,6 +151,12 @@ bool POLY_GRID_PARTITION::checkClearance( const VECTOR2I& aP, int aClearance ) int POLY_GRID_PARTITION::rescale_trunc( int aNumerator, int aValue, int aDenominator ) const { int64_t numerator = (int64_t) aNumerator * (int64_t) aValue; + + wxASSERT( aDenominator != 0 ); + + if( aDenominator == 0 ) // Avoid crash when divide by 0 + aDenominator = 1; + return numerator / aDenominator; }