From bce98376042bc1767042fff8b6dd400d943318eb Mon Sep 17 00:00:00 2001 From: Maxim Pashchenkov Date: Thu, 5 Mar 2020 11:52:10 +0300 Subject: [PATCH] Added assert for create Mat with negative dims, added tets for this case --- modules/gapi/include/opencv2/gapi/own/mat.hpp | 1 + modules/gapi/test/own/mat_tests.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/gapi/include/opencv2/gapi/own/mat.hpp b/modules/gapi/include/opencv2/gapi/own/mat.hpp index 9bf740d255..675a5bdaec 100644 --- a/modules/gapi/include/opencv2/gapi/own/mat.hpp +++ b/modules/gapi/include/opencv2/gapi/own/mat.hpp @@ -230,6 +230,7 @@ namespace cv { namespace gapi { namespace own { */ void create(Size _size, int _type) { + GAPI_Assert(_size.height >= 0 && _size.width >= 0); if (_size != Size{cols, rows} ) { Mat tmp{_size.height, _size.width, _type, nullptr}; diff --git a/modules/gapi/test/own/mat_tests.cpp b/modules/gapi/test/own/mat_tests.cpp index 27e816d722..fa3407a074 100644 --- a/modules/gapi/test/own/mat_tests.cpp +++ b/modules/gapi/test/own/mat_tests.cpp @@ -588,4 +588,23 @@ TEST(OwnMat, ROIView) << to_ocv(roi_view) << std::endl << expected_cv_mat << std::endl; } + +TEST(OwnMat, CreateWithNegativeDims) +{ + Mat own_mat; + ASSERT_ANY_THROW(own_mat.create(cv::Size{-1, -1}, CV_8U)); +} + +TEST(OwnMat, CreateWithNegativeWidth) +{ + Mat own_mat; + ASSERT_ANY_THROW(own_mat.create(cv::Size{-1, 1}, CV_8U)); +} + +TEST(OwnMat, CreateWithNegativeHeight) +{ + Mat own_mat; + ASSERT_ANY_THROW(own_mat.create(cv::Size{1, -1}, CV_8U)); +} + } // namespace opencv_test