From e6d9486a6cb3379a0eeb59bd405bea3125ea364d Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 23 Oct 2018 15:06:33 +0300 Subject: [PATCH] Fixed several issues found by static analysis --- modules/calib3d/src/calibration.cpp | 1 + modules/calib3d/src/chessboard.cpp | 4 +++- modules/core/include/opencv2/core/cvdef.h | 4 ++-- modules/dnn/src/layers/pooling_layer.cpp | 3 ++- modules/imgcodecs/src/grfmt_pfm.cpp | 2 +- modules/imgproc/src/contours.cpp | 1 + modules/objdetect/src/hog.cpp | 1 + 7 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index a6bc0afbc8..bca3dc8301 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -1133,6 +1133,7 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints, if( cvDet(&_RR) < 0 ) cvScale( &_RRt, &_RRt, -1 ); sc = cvNorm(&_RR); + CV_Assert(fabs(sc) > DBL_EPSILON); cvSVD( &_RR, &matW, &matU, &matV, CV_SVD_MODIFY_A + CV_SVD_U_T + CV_SVD_V_T ); cvGEMM( &matU, &matV, 1, 0, 0, &matR, CV_GEMM_A_T ); cvScale( &_tt, &_t, cvNorm(&matR)/sc ); diff --git a/modules/calib3d/src/chessboard.cpp b/modules/calib3d/src/chessboard.cpp index 240ef5262c..86c9e03750 100644 --- a/modules/calib3d/src/chessboard.cpp +++ b/modules/calib3d/src/chessboard.cpp @@ -164,7 +164,9 @@ cv::Mat findHomography1D(cv::InputArray _src,cv::InputArray _dst) Mat H = dst_T.inv()*Mat(H_, false)*src_T; // enforce frobeniusnorm of one - double scale = 1.0/cv::norm(H); + double scale = cv::norm(H); + CV_Assert(fabs(scale) > DBL_EPSILON); + scale = 1.0 / scale; return H*scale; } void polyfit(const Mat& src_x, const Mat& src_y, Mat& dst, int order) diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index cf97d53de8..42dcd36f7e 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -654,7 +654,7 @@ class float16_t public: #if CV_FP16_TYPE - float16_t() {} + float16_t() : h(0) {} explicit float16_t(float x) { h = (__fp16)x; } operator float() const { return (float)h; } static float16_t fromBits(ushort w) @@ -681,7 +681,7 @@ protected: __fp16 h; #else - float16_t() {} + float16_t() : w(0) {} explicit float16_t(float x) { #if CV_AVX2 diff --git a/modules/dnn/src/layers/pooling_layer.cpp b/modules/dnn/src/layers/pooling_layer.cpp index e1b7398c16..a0d22d073d 100644 --- a/modules/dnn/src/layers/pooling_layer.cpp +++ b/modules/dnn/src/layers/pooling_layer.cpp @@ -332,7 +332,8 @@ public: int poolingType; float spatialScale; - PoolingInvoker() : src(0), rois(0), dst(0), mask(0), avePoolPaddedArea(false), nstripes(0), + PoolingInvoker() : src(0), rois(0), dst(0), mask(0), pad_l(0), pad_t(0), pad_r(0), pad_b(0), + avePoolPaddedArea(false), nstripes(0), computeMaxIdx(0), poolingType(MAX), spatialScale(0) {} static void run(const Mat& src, const Mat& rois, Mat& dst, Mat& mask, Size kernel, diff --git a/modules/imgcodecs/src/grfmt_pfm.cpp b/modules/imgcodecs/src/grfmt_pfm.cpp index 0e4385b009..a09fc52aeb 100644 --- a/modules/imgcodecs/src/grfmt_pfm.cpp +++ b/modules/imgcodecs/src/grfmt_pfm.cpp @@ -79,7 +79,7 @@ PFMDecoder::~PFMDecoder() { } -PFMDecoder::PFMDecoder() +PFMDecoder::PFMDecoder() : m_scale_factor(0), m_swap_byte_order(false) { m_strm.close(); } diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index e584568bf0..43445bd375 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -1532,6 +1532,7 @@ icvFindContoursInInterval( const CvArr* src, tmp_prev->link = 0; // First line. None of runs is binded + tmp.pt.x = 0; tmp.pt.y = 0; CV_WRITE_SEQ_ELEM( tmp, writer ); upper_line = (CvLinkedRunPoint*)CV_GET_WRITTEN_ELEM( writer ); diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 348a66302d..963937cc69 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -240,6 +240,7 @@ void HOGDescriptor::computeGradient(InputArray _img, InputOutputArray _grad, Inp CV_INSTRUMENT_REGION(); Mat img = _img.getMat(); + CV_Assert(!img.empty()); CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 ); Size gradsize(img.cols + paddingTL.width + paddingBR.width,