From 5a340898b114e22e7be9bc5904a6a4110a3bc235 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 24 Nov 2018 13:21:35 -0300 Subject: [PATCH] lua: Don't allow negative dimensions in Sprite:resize() Fixes https://github.com/aseprite/api/issues/5 --- src/app/script/sprite_class.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/script/sprite_class.cpp b/src/app/script/sprite_class.cpp index c90086f68..60c1bb93b 100644 --- a/src/app/script/sprite_class.cpp +++ b/src/app/script/sprite_class.cpp @@ -40,6 +40,8 @@ #include "doc/slice.h" #include "doc/sprite.h" +#include + namespace app { namespace script { @@ -84,7 +86,12 @@ int Sprite_eq(lua_State* L) int Sprite_resize(lua_State* L) { auto sprite = get_docobj(L, 1); - const gfx::Size size = convert_args_into_size(L, 2); + gfx::Size size = convert_args_into_size(L, 2); + + // Fix invalid sizes + size.w = std::max(1, size.w); + size.h = std::max(1, size.h); + Doc* doc = static_cast(sprite->document()); Tx tx; DocApi(doc, tx).setSpriteSize(doc->sprite(), size.w, size.h);