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