From b0163f3937ff1e439516f66cf1adf20757635a2f Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 17 May 2019 18:11:14 -0300 Subject: [PATCH] Don't crash with div by zero when grid bounds has an invalid value --- src/app/snap_to_grid.cpp | 4 ++++ src/app/ui/editor/standby_state.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/snap_to_grid.cpp b/src/app/snap_to_grid.cpp index f43f04133..106ad8461 100644 --- a/src/app/snap_to_grid.cpp +++ b/src/app/snap_to_grid.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -21,6 +22,9 @@ gfx::Point snap_to_grid(const gfx::Rect& grid, const gfx::Point& point, const PreferSnapTo prefer) { + if (grid.isEmpty()) + return point; + gfx::Point newPoint; div_t d, dx, dy; diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 5ed9416b7..86be71fc0 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -597,10 +597,11 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) if (editor->docPref().show.grid()) { auto gb = editor->docPref().grid.bounds(); - int col = int((std::floor(spritePos.x) - (gb.x % gb.w)) / gb.w); - int row = int((std::floor(spritePos.y) - (gb.y % gb.h)) / gb.h); - sprintf( - buf+std::strlen(buf), " :grid: %d %d", col, row); + if (!gb.isEmpty()) { + int col = int((std::floor(spritePos.x) - (gb.x % gb.w)) / gb.w); + int row = int((std::floor(spritePos.y) - (gb.y % gb.h)) / gb.h); + sprintf(buf+std::strlen(buf), " :grid: %d %d", col, row); + } } if (editor->docPref().show.slices()) {