From: Alexander Alekhin Date: Tue, 1 Sep 2020 22:18:20 +0000 (+0000) Subject: backport: checks and fixes from static code analyzers results X-Git-Tag: submit/tizen/20210224.033012~2^2~15^2~34^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f2c83845d77a4e47adaed0d868ceef368630520;p=platform%2Fupstream%2Fopencv.git backport: checks and fixes from static code analyzers results original commit: 71f665bd8c3e39d6769aca1896237f836930f136 --- diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index 863f480..8b857a3 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -791,6 +791,7 @@ int ChessBoardDetector::orderFoundConnectedQuads(std::vector& q for (int i = 0; i < 4; i++) { + CV_DbgAssert(q); ChessBoardQuad *neighbor = q->neighbors[i]; switch(i) // adjust col, row for this quad { // start at top left, go clockwise @@ -1271,6 +1272,7 @@ int ChessBoardDetector::cleanFoundConnectedQuads(std::vector& q for (int i = 0; i < quad_count; ++i) { ChessBoardQuad *q = quad_group[i]; + CV_DbgAssert(q); for (int j = 0; j < 4; ++j) { if (q->neighbors[j] == q0) @@ -1328,6 +1330,7 @@ void ChessBoardDetector::findConnectedQuads(std::vector& out_gr stack.pop(); for (int k = 0; k < 4; k++ ) { + CV_DbgAssert(q); ChessBoardQuad *neighbor = q->neighbors[k]; if (neighbor && neighbor->count > 0 && neighbor->group_idx < 0 ) { @@ -1716,6 +1719,7 @@ void ChessBoardDetector::findQuadNeighbors() int k = 0; for (; k < 4; k++ ) { + CV_DbgAssert(q); if (!q->neighbors[k]) { if (normL2Sqr(closest_corner.pt - q->corners[k]->pt) < min_dist) @@ -2090,6 +2094,7 @@ void drawChessboardCorners( InputOutputArray image, Size patternSize, return; Mat corners = _corners.getMat(); const Point2f* corners_data = corners.ptr(0); + CV_DbgAssert(corners_data); int nelems = corners.checkVector(2, CV_32F, true); CV_Assert(nelems >= 0); diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 052bce1..710b1d7 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -978,9 +978,9 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints, int i, count; double a[9], ar[9]={1,0,0,0,1,0,0,0,1}, R[9]; - double MM[9], U[9], V[9], W[3]; + double MM[9] = { 0 }, U[9] = { 0 }, V[9] = { 0 }, W[3] = { 0 }; cv::Scalar Mc; - double param[6]; + double param[6] = { 0 }; CvMat matA = cvMat( 3, 3, CV_64F, a ); CvMat _Ar = cvMat( 3, 3, CV_64F, ar ); CvMat matR = cvMat( 3, 3, CV_64F, R ); @@ -1199,8 +1199,9 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints, CvMat matH = cvMat( 3, 3, CV_64F, H ); CvMat _f = cvMat( 2, 1, CV_64F, f ); - assert( CV_MAT_TYPE(npoints->type) == CV_32SC1 && - CV_IS_MAT_CONT(npoints->type) ); + CV_Assert(npoints); + CV_Assert(CV_MAT_TYPE(npoints->type) == CV_32SC1); + CV_Assert(CV_IS_MAT_CONT(npoints->type)); nimages = npoints->rows + npoints->cols - 1; if( (CV_MAT_TYPE(objectPoints->type) != CV_32FC3 && @@ -1221,6 +1222,9 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints, // extract vanishing points in order to obtain initial value for the focal length for( i = 0, pos = 0; i < nimages; i++, pos += ni ) { + CV_DbgAssert(npoints->data.i); + CV_DbgAssert(matA && matA->data.db); + CV_DbgAssert(_b && _b->data.db); double* Ap = matA->data.db + i*4; double* bp = _b->data.db + i*2; ni = npoints->data.i[i]; @@ -1231,6 +1235,7 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints, cvGetCols( imagePoints, &_m, pos, pos + ni ); cvFindHomography( &matM, &_m, &matH ); + CV_DbgAssert(_allH && _allH->data.db); memcpy( _allH->data.db + i*9, H, sizeof(H) ); H[0] -= H[6]*a[2]; H[1] -= H[7]*a[2]; H[2] -= H[8]*a[2]; @@ -3828,6 +3833,7 @@ static void adjust3rdMatrix(InputArrayOfArrays _imgpt1_0, double y1_ = 0, y2_ = 0, y1y1_ = 0, y1y2_ = 0; size_t n = imgpt1.size(); + CV_DbgAssert(n > 0); for( size_t i = 0; i < n; i++ ) { diff --git a/modules/dnn/src/layers/convolution_layer.cpp b/modules/dnn/src/layers/convolution_layer.cpp index f8ce75a..ddc318d 100644 --- a/modules/dnn/src/layers/convolution_layer.cpp +++ b/modules/dnn/src/layers/convolution_layer.cpp @@ -546,6 +546,8 @@ public: std::vector dims = ieInpNode->get_shape(); CV_Assert(dims.size() == 4 || dims.size() == 5); std::shared_ptr ieWeights = nodes.size() > 1 ? nodes[1].dynamicCast()->node : nullptr; + if (nodes.size() > 1) + CV_Assert(ieWeights); // dynamic_cast should not fail const int inpCn = dims[1]; const int inpGroupCn = nodes.size() > 1 ? ieWeights->get_shape()[1] : blobs[0].size[1]; const int group = inpCn / inpGroupCn; @@ -653,6 +655,7 @@ public: ParallelConv() : input_(0), weights_(0), output_(0), ngroups_(0), nstripes_(0), biasvec_(0), reluslope_(0), activ_(0), is1x1_(false), useAVX(false), useAVX2(false), useAVX512(false) + , blk_size_cn(0) {} static void run( const Mat& input, Mat& output, const Mat& weights, diff --git a/modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp b/modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp index eda2e83..8de7ba2 100644 --- a/modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp +++ b/modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp @@ -433,7 +433,7 @@ class OCL4DNNInnerProduct UMat& top_data); private: OCL4DNNInnerProductConfig config_; - int32_t axis_; + //int32_t axis_; int32_t num_output_; int32_t M_; int32_t N_; diff --git a/modules/flann/include/opencv2/flann/result_set.h b/modules/flann/include/opencv2/flann/result_set.h index 02f827a..47ad231 100644 --- a/modules/flann/include/opencv2/flann/result_set.h +++ b/modules/flann/include/opencv2/flann/result_set.h @@ -160,7 +160,8 @@ class KNNResultSet : public ResultSet DistanceType worst_distance_; public: - KNNResultSet(int capacity_) : capacity(capacity_), count(0) + KNNResultSet(int capacity_) + : indices(NULL), dists(NULL), capacity(capacity_), count(0), worst_distance_(0) { } @@ -186,6 +187,8 @@ public: void addPoint(DistanceType dist, int index) CV_OVERRIDE { + CV_DbgAssert(indices); + CV_DbgAssert(dists); if (dist >= worst_distance_) return; int i; for (i = count; i > 0; --i) { diff --git a/modules/flann/include/opencv2/flann/timer.h b/modules/flann/include/opencv2/flann/timer.h index 73795aa..7dc50a4 100644 --- a/modules/flann/include/opencv2/flann/timer.h +++ b/modules/flann/include/opencv2/flann/timer.h @@ -60,6 +60,7 @@ public: * Constructor. */ StartStopTimer() + : startTime(0) { reset(); } diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 46f580d..28dbdc8 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -429,6 +429,7 @@ icvSaveWindowPos( const char* name, CvRect rect ) CvRect cvGetWindowRect_W32(const char* name) { + RECT rect = { 0 }; CvRect result = cvRect(-1, -1, -1, -1); CV_FUNCNAME( "cvGetWindowRect_W32" ); @@ -443,7 +444,6 @@ CvRect cvGetWindowRect_W32(const char* name) if (!window) EXIT; // keep silence here - RECT rect; GetClientRect(window->hwnd, &rect); { POINT pt = {rect.left, rect.top}; @@ -513,7 +513,7 @@ void cvSetModeWindow_W32( const char* name, double prop_value)//Yannick Verdie if (window->status==CV_WINDOW_NORMAL && prop_value==CV_WINDOW_FULLSCREEN) { //save dimension - RECT rect; + RECT rect = { 0 }; GetWindowRect(window->frame, &rect); CvRect RectCV = cvRect(rect.left, rect.top,rect.right - rect.left, rect.bottom - rect.top); icvSaveWindowPos(window->name,RectCV ); @@ -1106,7 +1106,7 @@ static void icvScreenToClient( HWND hwnd, RECT* rect ) static RECT icvCalcWindowRect( CvWindow* window ) { const int gutter = 1; - RECT crect, trect, rect; + RECT crect = { 0 }, trect = { 0 } , rect = { 0 }; assert(window); @@ -1162,7 +1162,7 @@ static bool icvGetBitmapData( CvWindow* window, SIZE* size, int* channels, void* static void icvUpdateWindowPos( CvWindow* window ) { - RECT rect; + RECT rect = { 0 }; assert(window); if( (window->flags & CV_WINDOW_AUTOSIZE) && window->image ) @@ -1175,7 +1175,7 @@ static void icvUpdateWindowPos( CvWindow* window ) // toolbar may resize too for(i = 0; i < (window->toolbar.toolbar ? 2 : 1); i++) { - RECT rmw, rw = icvCalcWindowRect(window ); + RECT rmw = { 0 }, rw = icvCalcWindowRect(window ); MoveWindow(window->hwnd, rw.left, rw.top, rw.right - rw.left, rw.bottom - rw.top, FALSE); GetClientRect(window->hwnd, &rw); @@ -1362,7 +1362,7 @@ CV_IMPL void cvResizeWindow(const char* name, int width, int height ) int i; CvWindow* window; - RECT rmw, rw, rect; + RECT rmw = { 0 }, rw = { 0 }, rect = { 0 }; if( !name ) CV_ERROR( CV_StsNullPtr, "NULL name" ); @@ -1401,7 +1401,7 @@ CV_IMPL void cvMoveWindow( const char* name, int x, int y ) __BEGIN__; CvWindow* window; - RECT rect; + RECT rect = { 0 }; if( !name ) CV_ERROR( CV_StsNullPtr, "NULL name" ); @@ -1441,7 +1441,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) if( !(window->flags & CV_WINDOW_AUTOSIZE) ) { MINMAXINFO* minmax = (MINMAXINFO*)lParam; - RECT rect; + RECT rect = { 0 }; LRESULT retval = DefWindowProc(hwnd, uMsg, wParam, lParam); minmax->ptMinTrackSize.y = 100; @@ -1464,7 +1464,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) // Update the toolbar pos/size if(window->toolbar.toolbar) { - RECT rect; + RECT rect = { 0 }; GetWindowRect(window->toolbar.toolbar, &rect); MoveWindow(window->toolbar.toolbar, 0, 0, pos->cx, rect.bottom - rect.top, TRUE); } @@ -1480,7 +1480,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) // Snap window to screen edges with multi-monitor support. // Adi Shavit LPWINDOWPOS pos = (LPWINDOWPOS)lParam; - RECT rect; + RECT rect = { 0 }; GetWindowRect(window->frame, &rect); HMONITOR hMonitor; @@ -1531,7 +1531,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) pt.y = GET_Y_LPARAM( lParam ); ::ScreenToClient(hwnd, &pt); // Convert screen coordinates to client coordinates. - RECT rect; + RECT rect = { 0 }; GetClientRect( window->hwnd, &rect ); SIZE size = {0,0}; @@ -1558,7 +1558,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) case WM_ERASEBKGND: { - RECT cr, tr, wrc; + RECT cr = { 0 }, tr = { 0 }, wrc = { 0 }; HRGN rgn, rgn1, rgn2; int ret; HDC hdc = (HDC)wParam; @@ -1738,7 +1738,7 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM window->on_mouse( event, pt.x, pt.y, flags, window->on_mouse_param ); } else { // Full window is displayed using different size. Scale coordinates to match underlying positions. - RECT rect; + RECT rect = { 0 }; SIZE size = {0, 0}; GetClientRect( window->hwnd, &rect ); @@ -1798,7 +1798,7 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM } else { - RECT rect; + RECT rect = { 0 }; GetClientRect(window->hwnd, &rect); StretchBlt( hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, window->dc, 0, 0, size.cx, size.cy, SRCCOPY ); @@ -1955,7 +1955,7 @@ static LRESULT CALLBACK HGToolbarProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPAR for( ; trackbar != 0; trackbar = trackbar->next ) { - RECT rect; + RECT rect = { 0 }; SendMessage(window->toolbar.toolbar, TB_GETITEMRECT, (WPARAM)trackbar->id, (LPARAM)&rect); MoveWindow(trackbar->hwnd, rect.left + HG_BUDDY_WIDTH, rect.top, @@ -2180,7 +2180,7 @@ icvCreateTrackbar( const char* trackbar_name, const char* window_name, { TBBUTTON tbs = {}; TBBUTTONINFO tbis = {}; - RECT rect; + RECT rect = { 0 }; int bcount; int len = (int)strlen( trackbar_name ); diff --git a/modules/objdetect/src/cascadedetect_convert.cpp b/modules/objdetect/src/cascadedetect_convert.cpp index 1172cb7..20701b9 100644 --- a/modules/objdetect/src/cascadedetect_convert.cpp +++ b/modules/objdetect/src/cascadedetect_convert.cpp @@ -107,6 +107,8 @@ struct HaarClassifier struct HaarStageClassifier { + HaarStageClassifier() : threshold(0) {} + double threshold; std::vector weaks; };