From ea55a33b6026af293830bcb806c0724d04ca7c26 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 24 Sep 2022 20:38:49 -0500 Subject: [PATCH] [nostalgia/core] Fix possible div by zero in idxToPt --- src/nostalgia/core/ptidxconv.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nostalgia/core/ptidxconv.hpp b/src/nostalgia/core/ptidxconv.hpp index 6b5ec7f9..9c78b965 100644 --- a/src/nostalgia/core/ptidxconv.hpp +++ b/src/nostalgia/core/ptidxconv.hpp @@ -28,6 +28,10 @@ constexpr std::size_t ptToIdx(const geo::Point &pt, int c) noexcept { [[nodiscard]] constexpr geo::Point idxToPt(int i, int c) noexcept { + // prevent divide by zeros + if (!c) { + ++c; + } const auto t = i / PixelsPerTile; // tile number const auto iti = i % PixelsPerTile; // in tile index const auto tc = t % c; // tile column