Skip to content

Commit

Permalink
samples: handle corner cases (#25604)
Browse files Browse the repository at this point in the history
Ticket 145028
  • Loading branch information
Wovchena authored Jul 17, 2024
1 parent da58f14 commit 054c335
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/c/common/opencv_c_wrapper/src/bmp_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int readBmpImage(const char* fileName, BitMap* image) {
int padSize = image->width & 3;
size_t row_size = (size_t)image->width * 3;
char pad[3];
size_t size = row_size * image->height;
size_t size = row_size * (size_t)image->height;

image->data = malloc(sizeof(char) * size);
if (NULL == image->data) {
Expand Down
6 changes: 6 additions & 0 deletions samples/cpp/common/utils/include/samples/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ static UNUSED void addRectangles(unsigned char* data,
std::vector<int> rectangles,
std::vector<int> classes,
int thickness) {
if (height <= 0) {
throw std::runtime_error("height must be greater than 0");
}
if (width <= 0) {
throw std::runtime_error("width must be greater than 0");
}
struct Color {
unsigned char red;
unsigned char green;
Expand Down

0 comments on commit 054c335

Please sign in to comment.