Skip to content

Commit ff90f27

Browse files
committed
Merge pull request opencv#4169 from alalek:issue_4457
2 parents 0b99f70 + 0661739 commit ff90f27

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

modules/core/include/opencv2/core/mat.inl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step)
397397
data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0),
398398
allocator(0), u(0), size(&rows)
399399
{
400+
CV_Assert(total() == 0 || data != NULL);
401+
400402
size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type);
401403
size_t minstep = cols * esz;
402404
if( _step == AUTO_STEP )
@@ -428,6 +430,8 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step)
428430
data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0),
429431
allocator(0), u(0), size(&rows)
430432
{
433+
CV_Assert(total() == 0 || data != NULL);
434+
431435
size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type);
432436
size_t minstep = cols*esz;
433437
if( _step == AUTO_STEP )

modules/core/src/matop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,12 +1583,12 @@ void MatOp_Initializer::multiply(const MatExpr& e, double s, MatExpr& res) const
15831583

15841584
inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, Size sz, int type, double alpha)
15851585
{
1586-
res = MatExpr(getGlobalMatOpInitializer(), method, Mat(sz, type, (void*)0), Mat(), Mat(), alpha, 0);
1586+
res = MatExpr(getGlobalMatOpInitializer(), method, Mat(sz, type, (void*)0xEEEEEEEE), Mat(), Mat(), alpha, 0);
15871587
}
15881588

15891589
inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, int ndims, const int* sizes, int type, double alpha)
15901590
{
1591-
res = MatExpr(getGlobalMatOpInitializer(), method, Mat(ndims, sizes, type, (void*)0), Mat(), Mat(), alpha, 0);
1591+
res = MatExpr(getGlobalMatOpInitializer(), method, Mat(ndims, sizes, type, (void*)0xEEEEEEEE), Mat(), Mat(), alpha, 0);
15921592
}
15931593

15941594
///////////////////////////////////////////////////////////////////////////////////////////////////////////

modules/core/test/test_mat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,11 @@ TEST(Core_IOArray, submat_create)
11781178
EXPECT_THROW( OutputArray_create2(A.row(0)), cv::Exception );
11791179
}
11801180

1181+
TEST(Core_Mat, issue4457_pass_null_ptr)
1182+
{
1183+
ASSERT_ANY_THROW(cv::Mat mask(45, 45, CV_32F, 0));
1184+
}
1185+
11811186
TEST(Core_Mat, reshape_1942)
11821187
{
11831188
cv::Mat A = (cv::Mat_<float>(2,3) << 3.4884074, 1.4159607, 0.78737736, 2.3456569, -0.88010466, 0.3009364);

0 commit comments

Comments
 (0)