Skip to content

Commit 9565640

Browse files
committed
Fix bounds checks in fill_rect & draw_rect methods
1 parent 2eb80f7 commit 9565640

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/BitmapPlusPlus.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace bmp {
162162
*/
163163
void fill_rect(const std::int32_t x, const std::int32_t y, const std::int32_t width, const std::int32_t height,
164164
const Pixel color) {
165-
if (!in_bounds(x, y) || !in_bounds(x + width, y + height))
165+
if (!in_bounds(x, y) || !in_bounds(x + (width - 1), y + (height - 1)))
166166
throw Exception(
167167
"Bitmap::fill_rect(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(width) + ", " +
168168
std::to_string(height) + "): x,y,w or h out of bounds");
@@ -179,7 +179,7 @@ namespace bmp {
179179
*/
180180
void draw_rect(const std::int32_t x, const std::int32_t y, const std::int32_t width, const std::int32_t height,
181181
const Pixel color) {
182-
if (!in_bounds(x, y) || !in_bounds(x + width, y + height))
182+
if (!in_bounds(x, y) || !in_bounds(x + (width - 1), y + (height - 1)))
183183
throw Exception(
184184
"Bitmap::draw_rect(" + std::to_string(x) + ", " + std::to_string(y) + ", " + std::to_string(width) + ", " +
185185
std::to_string(height) + "): x,y,w or h out of bounds");

0 commit comments

Comments
 (0)