From a6f46d7bb1305ef9a5eee7b1a7f8013be0429f7d Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 2 Jul 2015 15:10:12 +0300 Subject: [PATCH] issue 4457 --- modules/core/include/opencv2/core/mat.inl.hpp | 4 ++++ modules/core/test/test_mat.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 64d40876b..ba52efde1 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -397,6 +397,8 @@ Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), allocator(0), u(0), size(&rows) { + CV_Assert(total() == 0 || data != NULL); + size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); size_t minstep = cols * esz; if( _step == AUTO_STEP ) @@ -428,6 +430,8 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), allocator(0), u(0), size(&rows) { + CV_Assert(total() == 0 || data != NULL); + size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); size_t minstep = cols*esz; if( _step == AUTO_STEP ) diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 00a99d8e2..e2d4e8a4b 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -1178,6 +1178,11 @@ TEST(Core_IOArray, submat_create) EXPECT_THROW( OutputArray_create2(A.row(0)), cv::Exception ); } +TEST(Core_Mat, issue4457_pass_null_ptr) +{ + ASSERT_ANY_THROW(cv::Mat mask(45, 45, CV_32F, 0)); +} + TEST(Core_Mat, reshape_1942) { cv::Mat A = (cv::Mat_(2,3) << 3.4884074, 1.4159607, 0.78737736, 2.3456569, -0.88010466, 0.3009364);