From a74a2302aa875ef6da02a37b7d7fccfd25781cba Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 4 Sep 2012 13:34:52 +0400 Subject: [PATCH] fixed bug #2331 --- modules/core/src/copy.cpp | 1 + modules/core/test/test_operations.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 84bc22476..84732e37a 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -209,6 +209,7 @@ void Mat::copyTo( OutputArray _dst ) const int dtype = _dst.type(); if( _dst.fixedType() && dtype != type() ) { + CV_Assert( channels() == CV_MAT_CN(dtype) ); convertTo( _dst, dtype ); return; } diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index 86a90c8dc..6b5f6e0cc 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -766,6 +766,19 @@ bool CV_OperationsTest::TestTemplateMat() Mat c = (a*b.t()).t(); CV_Assert( norm(c, CV_L1) == 4. ); } + + bool badarg_catched = false; + try + { + Mat m1 = Mat::zeros(1, 10, CV_8UC1); + Mat m2 = Mat::zeros(10, 10, CV_8UC3); + m1.copyTo(m2.row(1)); + } + catch(const Exception& e) + { + badarg_catched = true; + } + CV_Assert( badarg_catched ); } catch (const test_excep& e) {