From 93a34cc68d6a3df2ca14e64e6578920b0dd0f8d7 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Fri, 4 Mar 2016 15:13:55 +0000 Subject: [PATCH] raster scaling: check for division by zero --- include/mapnik/span_image_filter.hpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/include/mapnik/span_image_filter.hpp b/include/mapnik/span_image_filter.hpp index 29049beef..14ef7eb75 100644 --- a/include/mapnik/span_image_filter.hpp +++ b/include/mapnik/span_image_filter.hpp @@ -131,19 +131,27 @@ public: fg_ptr = reinterpret_cast(base_type::source().next_y()); } - fg /= total_weight; - if (fg < std::numeric_limits::min()) + if (total_weight == 0) { - span->v = std::numeric_limits::min(); - } - else if (fg > std::numeric_limits::max()) - { - span->v = std::numeric_limits::max(); + span->v = *nodata_value_; } else { - span->v = static_cast(fg); + fg /= total_weight; + if (fg < std::numeric_limits::min()) + { + span->v = std::numeric_limits::min(); + } + else if (fg > std::numeric_limits::max()) + { + span->v = std::numeric_limits::max(); + } + else + { + span->v = static_cast(fg); + } } + span->a = base_mask; ++span;