From: Ilya Lavrenov Date: Sun, 23 Feb 2014 10:59:06 +0000 (+0400) Subject: fixed defects from coverity.com X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~585^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32eb38ec984b098b56b3358d8ba5edd0b721c6ed;p=profile%2Fivi%2Fopencv.git fixed defects from coverity.com --- diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index 844fde4..ca2121b 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -1998,7 +1998,7 @@ bool cv::findCirclesGrid( InputArray _image, Size patternSize, { isFound = boxFinder.findHoles(); } - catch (cv::Exception) + catch (const cv::Exception &) { } diff --git a/modules/calib3d/src/compat_ptsetreg.cpp b/modules/calib3d/src/compat_ptsetreg.cpp index e8f4108..50ba347 100644 --- a/modules/calib3d/src/compat_ptsetreg.cpp +++ b/modules/calib3d/src/compat_ptsetreg.cpp @@ -57,6 +57,7 @@ CvLevMarq::CvLevMarq() criteria = cvTermCriteria(0,0,0); iters = 0; completeSymmFlag = false; + errNorm = prevErrNorm = DBL_MAX; } CvLevMarq::CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria0, bool _completeSymmFlag ) @@ -101,7 +102,7 @@ void CvLevMarq::init( int nparams, int nerrs, CvTermCriteria criteria0, bool _co J.reset(cvCreateMat( nerrs, nparams, CV_64F )); err.reset(cvCreateMat( nerrs, 1, CV_64F )); } - prevErrNorm = DBL_MAX; + errNorm = prevErrNorm = DBL_MAX; lambdaLg10 = -3; criteria = criteria0; if( criteria.type & CV_TERMCRIT_ITER ) diff --git a/modules/calib3d/src/epnp.h b/modules/calib3d/src/epnp.h index fe01606..dd42b01 100644 --- a/modules/calib3d/src/epnp.h +++ b/modules/calib3d/src/epnp.h @@ -74,7 +74,6 @@ class epnp { int number_of_correspondences; double cws[4][3], ccs[4][3]; - double cws_determinant; int max_nr; double * A1, * A2; }; diff --git a/modules/calib3d/src/ptsetreg.cpp b/modules/calib3d/src/ptsetreg.cpp index 1bf35eb..3c43624 100644 --- a/modules/calib3d/src/ptsetreg.cpp +++ b/modules/calib3d/src/ptsetreg.cpp @@ -260,7 +260,6 @@ public: Ptr cb; int modelPoints; - int maxBasicSolutions; bool checkPartialSubsets; double threshold; double confidence; diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 8366f77..16fbc32 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -1393,6 +1393,7 @@ void CV_StereoCalibrationTest::run( int ) { ts->printf( cvtest::TS::LOG, "The file %s can not be opened or has invalid content\n", filepath.c_str() ); ts->set_failed_test_info( f ? cvtest::TS::FAIL_INVALID_TEST_DATA : cvtest::TS::FAIL_MISSING_TEST_DATA ); + fclose(f); return; } diff --git a/modules/calib3d/test/test_cameracalibration_artificial.cpp b/modules/calib3d/test/test_cameracalibration_artificial.cpp index 1ff13c9..07e5894 100644 --- a/modules/calib3d/test/test_cameracalibration_artificial.cpp +++ b/modules/calib3d/test/test_cameracalibration_artificial.cpp @@ -85,7 +85,8 @@ Mat calcRvec(const vector& points, const Size& cornerSize) class CV_CalibrateCameraArtificialTest : public cvtest::BaseTest { public: - CV_CalibrateCameraArtificialTest() + CV_CalibrateCameraArtificialTest() : + r(0) { } ~CV_CalibrateCameraArtificialTest() {} diff --git a/modules/calib3d/test/test_chesscorners.cpp b/modules/calib3d/test/test_chesscorners.cpp index 17ecb67..44e7e6c 100644 --- a/modules/calib3d/test/test_chesscorners.cpp +++ b/modules/calib3d/test/test_chesscorners.cpp @@ -309,7 +309,8 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename ) progress = update_progress( progress, idx, max_idx, 0 ); } - sum_error /= count; + if (count != 0) + sum_error /= count; ts->printf(cvtest::TS::LOG, "Average error is %f\n", sum_error); } diff --git a/modules/calib3d/test/test_chesscorners_badarg.cpp b/modules/calib3d/test/test_chesscorners_badarg.cpp index 318912e..520d8df 100644 --- a/modules/calib3d/test/test_chesscorners_badarg.cpp +++ b/modules/calib3d/test/test_chesscorners_badarg.cpp @@ -89,7 +89,14 @@ protected: } }; -CV_ChessboardDetectorBadArgTest::CV_ChessboardDetectorBadArgTest() {} +CV_ChessboardDetectorBadArgTest::CV_ChessboardDetectorBadArgTest() +{ + cpp = false; + flags = 0; + out_corners = NULL; + out_corner_count = NULL; + drawCorners = was_found = false; +} /* ///////////////////// chess_corner_test ///////////////////////// */ void CV_ChessboardDetectorBadArgTest::run( int /*start_from */) diff --git a/modules/calib3d/test/test_cornerssubpix.cpp b/modules/calib3d/test/test_cornerssubpix.cpp index 4426d5e..d1f0776 100644 --- a/modules/calib3d/test/test_cornerssubpix.cpp +++ b/modules/calib3d/test/test_cornerssubpix.cpp @@ -211,6 +211,7 @@ void CV_ChessboardSubpixelTest::run( int ) progress = update_progress( progress, i-1, runs_count, 0 ); } + ASSERT_NE(0, count); sum_dist /= count; ts->printf(cvtest::TS::LOG, "Average error after findCornerSubpix: %f\n", sum_dist); diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index 7e6f9a8..749faf1 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -808,6 +808,7 @@ CV_FundamentalMatTest::CV_FundamentalMatTest() method = 0; img_size = 10; cube_size = 10; + dims = 0; min_f = 1; max_f = 3; sigma = 0;//0.1; @@ -1086,7 +1087,6 @@ protected: int img_size; int cube_size; int dims; - int e_result; double min_f, max_f; double sigma; }; @@ -1124,9 +1124,10 @@ CV_EssentialMatTest::CV_EssentialMatTest() method = 0; img_size = 10; cube_size = 10; + dims = 0; min_f = 1; max_f = 3; - + sigma = 0; } diff --git a/modules/calib3d/test/test_undistort.cpp b/modules/calib3d/test/test_undistort.cpp index 959d8be..cd6af12 100644 --- a/modules/calib3d/test/test_undistort.cpp +++ b/modules/calib3d/test/test_undistort.cpp @@ -75,6 +75,9 @@ CV_DefaultNewCameraMatrixTest::CV_DefaultNewCameraMatrixTest() test_array[INPUT].push_back(NULL); test_array[OUTPUT].push_back(NULL); test_array[REF_OUTPUT].push_back(NULL); + + matrix_type = 0; + center_principal_point = false; } void CV_DefaultNewCameraMatrixTest::get_test_array_types_and_sizes( int test_case_idx, vector >& sizes, vector >& types ) @@ -200,6 +203,9 @@ CV_UndistortPointsTest::CV_UndistortPointsTest() test_array[OUTPUT].push_back(NULL); // distorted dst points test_array[TEMP].push_back(NULL); // dst points test_array[REF_OUTPUT].push_back(NULL); + + useCPlus = useDstMat = false; + zero_new_cam = zero_distortion = zero_R = false; } void CV_UndistortPointsTest::get_test_array_types_and_sizes( int test_case_idx, vector >& sizes, vector >& types ) @@ -605,6 +611,11 @@ CV_InitUndistortRectifyMapTest::CV_InitUndistortRectifyMapTest() test_array[INPUT].push_back(NULL); // new camera matrix test_array[OUTPUT].push_back(NULL); // distorted dst points test_array[REF_OUTPUT].push_back(NULL); + + useCPlus = false; + zero_distortion = zero_new_cam = zero_R = false; + _mapx = _mapy = NULL; + mat_type = 0; } void CV_InitUndistortRectifyMapTest::get_test_array_types_and_sizes( int test_case_idx, vector >& sizes, vector >& types ) diff --git a/modules/calib3d/test/test_undistort_badarg.cpp b/modules/calib3d/test/test_undistort_badarg.cpp index 60460a5..f3f762f 100644 --- a/modules/calib3d/test/test_undistort_badarg.cpp +++ b/modules/calib3d/test/test_undistort_badarg.cpp @@ -78,6 +78,8 @@ private: CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest () { + useCPlus = false; + _camera_mat = matR = matP = _distortion_coeffs = _src_points = _dst_points = NULL; } void CV_UndistortPointsBadArgTest::run_func() @@ -311,6 +313,8 @@ private: CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest () { + useCPlus = false; + _camera_mat = matR = _new_camera_mat = _distortion_coeffs = _mapx = _mapy = NULL; } void CV_InitUndistortRectifyMapBadArgTest::run_func() @@ -431,6 +435,8 @@ private: CV_UndistortBadArgTest::CV_UndistortBadArgTest () { + useCPlus = false; + _camera_mat = _new_camera_mat = _distortion_coeffs = _src = _dst = NULL; } void CV_UndistortBadArgTest::run_func() diff --git a/modules/contrib/include/opencv2/contrib.hpp b/modules/contrib/include/opencv2/contrib.hpp index f5a4323..1770c0b 100644 --- a/modules/contrib/include/opencv2/contrib.hpp +++ b/modules/contrib/include/opencv2/contrib.hpp @@ -55,7 +55,7 @@ class CV_EXPORTS Octree public: struct Node { - Node() {} + Node() { memset(this, 0, sizeof(Node)); } int begin, end; float x_min, x_max, y_min, y_max, z_min, z_max; int maxLevels; diff --git a/modules/core/include/opencv2/core/utility.hpp b/modules/core/include/opencv2/core/utility.hpp index 191d696..3e844cc 100644 --- a/modules/core/include/opencv2/core/utility.hpp +++ b/modules/core/include/opencv2/core/utility.hpp @@ -340,6 +340,8 @@ class CV_EXPORTS CommandLineParser CommandLineParser(const CommandLineParser& parser); CommandLineParser& operator = (const CommandLineParser& parser); + ~CommandLineParser(); + String getPathToApplication() const; template diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 2818e75..0238a99 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -237,6 +237,11 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const S impl->sort_params(); } +CommandLineParser::~CommandLineParser() +{ + if (CV_XADD(&impl->refcount, -1) == 1) + delete impl; +} CommandLineParser::CommandLineParser(const CommandLineParser& parser) { diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index c7f18dc..6fe1cf5 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2641,9 +2641,9 @@ KernelArg KernelArg::Constant(const Mat& m) struct Kernel::Impl { - Impl(const char* kname, const Program& prog) + Impl(const char* kname, const Program& prog) : + refcount(1), e(0), nu(0) { - e = 0; refcount = 1; cl_program ph = (cl_program)prog.ptr(); cl_int retval = 0; handle = ph != 0 ? diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index b432042..626b44c 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -18,7 +18,7 @@ struct BaseElemWiseOp BaseElemWiseOp(int _ninputs, int _flags, double _alpha, double _beta, Scalar _gamma=Scalar::all(0), int _context=1) : ninputs(_ninputs), flags(_flags), alpha(_alpha), beta(_beta), gamma(_gamma), context(_context) {} - BaseElemWiseOp() { flags = 0; alpha = beta = 0; gamma = Scalar::all(0); } + BaseElemWiseOp() { flags = 0; alpha = beta = 0; gamma = Scalar::all(0); ninputs = 0; context = 1; } virtual ~BaseElemWiseOp() {} virtual void op(const vector&, Mat&, const Mat&) {} virtual void refop(const vector&, Mat&, const Mat&) {} @@ -89,7 +89,6 @@ struct BaseElemWiseOp double alpha; double beta; Scalar gamma; - int maxErr; int context; }; @@ -409,7 +408,7 @@ struct MaxSOp : public BaseElemWiseOp struct CmpOp : public BaseElemWiseOp { - CmpOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} + CmpOp() : BaseElemWiseOp(2, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) { cmpop = 0; } void generateScalars(int depth, RNG& rng) { BaseElemWiseOp::generateScalars(depth, rng); @@ -437,7 +436,7 @@ struct CmpOp : public BaseElemWiseOp struct CmpSOp : public BaseElemWiseOp { - CmpSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) {} + CmpSOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+REAL_GAMMA, 1, 1, Scalar::all(0)) { cmpop = 0; } void generateScalars(int depth, RNG& rng) { BaseElemWiseOp::generateScalars(depth, rng); @@ -467,7 +466,7 @@ struct CmpSOp : public BaseElemWiseOp struct CopyOp : public BaseElemWiseOp { - CopyOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)) {} + CopyOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK, 1, 1, Scalar::all(0)) { } void op(const vector& src, Mat& dst, const Mat& mask) { src[0].copyTo(dst, mask); @@ -484,7 +483,6 @@ struct CopyOp : public BaseElemWiseOp { return 0; } - int cmpop; }; @@ -810,7 +808,7 @@ static void setIdentity(Mat& dst, const Scalar& s) struct FlipOp : public BaseElemWiseOp { - FlipOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) {} + FlipOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA, 1, 1, Scalar::all(0)) { flipcode = 0; } void getRandomSize(RNG& rng, vector& size) { cvtest::randomSize(rng, 2, 2, cvtest::ARITHM_MAX_SIZE_LOG, size); diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index 1ea7b6f..859ebe6 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -617,6 +617,7 @@ Core_GEMMTest::Core_GEMMTest() : Core_MatrixTest( 5, 1, false, false, 2 ) { test_case_count = 100; max_log_array_size = 10; + tabc_flag = 0; alpha = beta = 0; } @@ -821,6 +822,8 @@ protected: Core_TransformTest::Core_TransformTest() : Core_MatrixTest( 3, 1, true, false, 4 ) { + scale = 1; + diagMtx = false; } @@ -1154,7 +1157,7 @@ protected: Core_CovarMatrixTest::Core_CovarMatrixTest() : Core_MatrixTest( 1, 1, true, false, 1 ), -flags(0), t_flag(0), are_images(false) + flags(0), t_flag(0), len(0), count(0), are_images(false) { test_case_count = 100; test_array[INPUT_OUTPUT].push_back(NULL); diff --git a/modules/features2d/src/bagofwords.cpp b/modules/features2d/src/bagofwords.cpp index 5cbbc55..525e478 100644 --- a/modules/features2d/src/bagofwords.cpp +++ b/modules/features2d/src/bagofwords.cpp @@ -44,7 +44,7 @@ namespace cv { -BOWTrainer::BOWTrainer() +BOWTrainer::BOWTrainer() : size(0) {} BOWTrainer::~BOWTrainer() diff --git a/modules/features2d/src/brisk.cpp b/modules/features2d/src/brisk.cpp index da982db..f4690eb 100644 --- a/modules/features2d/src/brisk.cpp +++ b/modules/features2d/src/brisk.cpp @@ -224,6 +224,8 @@ BRISK::BRISK(std::vector &radiusList, std::vector &numberList, float std::vector indexChange) { generateKernel(radiusList, numberList, dMax, dMin, indexChange); + threshold = 20; + octaves = 3; } void diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 6dccef9..31a8b1b 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -540,8 +540,6 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, int wtype = CV_MAKETYPE(wdepth, src.channels()); Mat kd, ks; getSobelKernels( kd, ks, 2, 0, ksize, false, ktype ); - if( ddepth < 0 ) - ddepth = src.depth(); int dtype = CV_MAKETYPE(ddepth, src.channels()); int dy0 = std::min(std::max((int)(STRIPE_SIZE/(getElemSize(src.type())*src.cols)), 1), src.rows); diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 09519e7..8a4c742 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -1405,7 +1405,11 @@ struct SymmColumnVec_32f16s struct RowVec_32f { - RowVec_32f() {} + RowVec_32f() + { + haveSSE = checkHardwareSupport(CV_CPU_SSE); + } + RowVec_32f( const Mat& _kernel ) { kernel = _kernel; diff --git a/modules/imgproc/test/test_color.cpp b/modules/imgproc/test/test_color.cpp index 0c94f8f..cf420fd 100644 --- a/modules/imgproc/test/test_color.cpp +++ b/modules/imgproc/test/test_color.cpp @@ -99,6 +99,8 @@ CV_ColorCvtBaseTest::CV_ColorCvtBaseTest( bool _custom_inv_transform, bool _allo test_cpp = false; hue_range = 0; + blue_idx = 0; + inplace = false; } diff --git a/modules/ml/src/precomp.hpp b/modules/ml/src/precomp.hpp index 06b8f4f..551ff81 100644 --- a/modules/ml/src/precomp.hpp +++ b/modules/ml/src/precomp.hpp @@ -351,7 +351,7 @@ namespace cv { struct DTreeBestSplitFinder { - DTreeBestSplitFinder(){ tree = 0; node = 0; } + DTreeBestSplitFinder(){ splitSize = 0, tree = 0; node = 0; } DTreeBestSplitFinder( CvDTree* _tree, CvDTreeNode* _node); DTreeBestSplitFinder( const DTreeBestSplitFinder& finder, Split ); virtual ~DTreeBestSplitFinder() {} diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 318f9e0..89c91b9 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -2897,7 +2897,7 @@ static std::ostream& operator << (std::ostream& out, const MatPart& m) } MatComparator::MatComparator(double _maxdiff, int _context) - : maxdiff(_maxdiff), context(_context) {} + : maxdiff(_maxdiff), realmaxdiff(DBL_MAX), context(_context) {} ::testing::AssertionResult MatComparator::operator()(const char* expr1, const char* expr2, diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 5c1c32b..8060e27 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -855,6 +855,9 @@ int64 TestBase::_calibrate() #endif TestBase::TestBase(): testStrategy(PERF_STRATEGY_DEFAULT), declare(this) { + lastTime = totalTime = timeLimit = 0; + nIters = currentIter = runsPerIteration = 0; + verified = false; } #ifdef _MSC_VER # pragma warning(pop) diff --git a/modules/video/src/simpleflow.cpp b/modules/video/src/simpleflow.cpp index 765a342..66f4c41 100644 --- a/modules/video/src/simpleflow.cpp +++ b/modules/video/src/simpleflow.cpp @@ -429,6 +429,7 @@ static inline float extrapolateValueInRect(int height, int width, if (r == height && c == 0) { return v21;} if (r == height && c == width) { return v22;} + CV_Assert(height > 0 && width > 0); float qr = float(r) / height; float pr = 1.0f - qr; float qc = float(c) / width;