From 04674b6ae8517bf77b000f28ae5e2ab4642689d3 Mon Sep 17 00:00:00 2001 From: Joseph Gelfand Date: Sat, 6 Oct 2018 08:32:00 -0600 Subject: [PATCH] Made Blitting more permissive (#3584) Made Blitting more permissive SDL_BlitSurface's documentation (https://wiki.libsdl.org/SDL_BlitSurface) notes that "Blits with negative dstrect coordinates will be clipped properly". Looking at the source code for SDL_UpperBlit() convinced me that dstrect coordinates that were too big would also be handled appropriately. Fixes #2225. --- src/image_modifications.cpp | 22 ++++++++++------------ src/tests/test_image_modifications.cpp | 5 +++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/image_modifications.cpp b/src/image_modifications.cpp index 53592283f4ca..74ed66ad134b 100644 --- a/src/image_modifications.cpp +++ b/src/image_modifications.cpp @@ -407,20 +407,18 @@ surface blit_modification::operator()(const surface& src) const throw imod_exception(sstr); } - if(surf_->w + x_ > src->w) { + if(surf_->w + x_ < 0) { std::stringstream sstr; sstr << "~BLIT(): offset and width '" - << x_ + surf_->w << "' larger than destination image's width '" - << src->w << "' no blitting performed.\n"; + << x_ + surf_->w << "' less than zero no blitting performed.\n"; throw imod_exception(sstr); } - if(surf_->h + y_ > src->h) { + if(surf_->h + y_ < 0) { std::stringstream sstr; sstr << "~BLIT(): offset and height '" - << y_ + surf_->h << "' larger than destination image's height '" - << src->h << "' no blitting performed.\n"; + << y_ + surf_->h << "' less than zero no blitting performed.\n"; throw imod_exception(sstr); } @@ -1015,7 +1013,12 @@ REGISTER_MOD_PARSER(BLIT, args) ERR_DP << "no arguments passed to the ~BLIT() function" << std::endl; return nullptr; } - + + if(s > 3){ + ERR_DP << "too many arguments passed to the ~BLIT() function" << std::endl; + return nullptr; + } + int x = 0, y = 0; if(s == 3) { @@ -1023,11 +1026,6 @@ REGISTER_MOD_PARSER(BLIT, args) y = lexical_cast_default(param[2]); } - if(x < 0 || y < 0) { - ERR_DP << "negative position arguments in ~BLIT() function" << std::endl; - return nullptr; - } - const image::locator img(param[0]); std::stringstream message; message << "~BLIT():"; diff --git a/src/tests/test_image_modifications.cpp b/src/tests/test_image_modifications.cpp index 61bf452442d5..e6745ae7553a 100644 --- a/src/tests/test_image_modifications.cpp +++ b/src/tests/test_image_modifications.cpp @@ -502,9 +502,10 @@ BOOST_AUTO_TEST_CASE(test_blit_modification_decoding_invalid_args) modification::decode("~BLIT()" "~BLIT(wesnoth-icon.png,1,-2)" "~BLIT(wesnoth-icon.png,-1,2)" - "~BLIT(wesnoth-icon.png,-1,-2)"); + "~BLIT(wesnoth-icon.png,-1,-2)" + "~BLIT(wesnoth-icon.png,1,2,3)"); - BOOST_CHECK_EQUAL(queue.size(), 0); + BOOST_CHECK_EQUAL(queue.size(), 3); } /** Tests if the MASK modification with one argument is correctly decoded