Skip to content

Commit fa11b98

Browse files
committed
Merge pull request opencv#18255 from alalek:backport_18243
2 parents 64c67a9 + 1f2c838 commit fa11b98

File tree

8 files changed

+42
-22
lines changed

8 files changed

+42
-22
lines changed

modules/calib3d/src/calibinit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ int ChessBoardDetector::orderFoundConnectedQuads(std::vector<ChessBoardQuad*>& q
791791

792792
for (int i = 0; i < 4; i++)
793793
{
794+
CV_DbgAssert(q);
794795
ChessBoardQuad *neighbor = q->neighbors[i];
795796
switch(i) // adjust col, row for this quad
796797
{ // start at top left, go clockwise
@@ -1271,6 +1272,7 @@ int ChessBoardDetector::cleanFoundConnectedQuads(std::vector<ChessBoardQuad*>& q
12711272
for (int i = 0; i < quad_count; ++i)
12721273
{
12731274
ChessBoardQuad *q = quad_group[i];
1275+
CV_DbgAssert(q);
12741276
for (int j = 0; j < 4; ++j)
12751277
{
12761278
if (q->neighbors[j] == q0)
@@ -1328,6 +1330,7 @@ void ChessBoardDetector::findConnectedQuads(std::vector<ChessBoardQuad*>& out_gr
13281330
stack.pop();
13291331
for (int k = 0; k < 4; k++ )
13301332
{
1333+
CV_DbgAssert(q);
13311334
ChessBoardQuad *neighbor = q->neighbors[k];
13321335
if (neighbor && neighbor->count > 0 && neighbor->group_idx < 0 )
13331336
{
@@ -1716,6 +1719,7 @@ void ChessBoardDetector::findQuadNeighbors()
17161719
int k = 0;
17171720
for (; k < 4; k++ )
17181721
{
1722+
CV_DbgAssert(q);
17191723
if (!q->neighbors[k])
17201724
{
17211725
if (normL2Sqr<float>(closest_corner.pt - q->corners[k]->pt) < min_dist)
@@ -2090,6 +2094,7 @@ void drawChessboardCorners( InputOutputArray image, Size patternSize,
20902094
return;
20912095
Mat corners = _corners.getMat();
20922096
const Point2f* corners_data = corners.ptr<Point2f>(0);
2097+
CV_DbgAssert(corners_data);
20932098
int nelems = corners.checkVector(2, CV_32F, true);
20942099
CV_Assert(nelems >= 0);
20952100

modules/calib3d/src/calibration.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,9 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
978978

979979
int i, count;
980980
double a[9], ar[9]={1,0,0,0,1,0,0,0,1}, R[9];
981-
double MM[9], U[9], V[9], W[3];
981+
double MM[9] = { 0 }, U[9] = { 0 }, V[9] = { 0 }, W[3] = { 0 };
982982
cv::Scalar Mc;
983-
double param[6];
983+
double param[6] = { 0 };
984984
CvMat matA = cvMat( 3, 3, CV_64F, a );
985985
CvMat _Ar = cvMat( 3, 3, CV_64F, ar );
986986
CvMat matR = cvMat( 3, 3, CV_64F, R );
@@ -1199,8 +1199,9 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
11991199
CvMat matH = cvMat( 3, 3, CV_64F, H );
12001200
CvMat _f = cvMat( 2, 1, CV_64F, f );
12011201

1202-
assert( CV_MAT_TYPE(npoints->type) == CV_32SC1 &&
1203-
CV_IS_MAT_CONT(npoints->type) );
1202+
CV_Assert(npoints);
1203+
CV_Assert(CV_MAT_TYPE(npoints->type) == CV_32SC1);
1204+
CV_Assert(CV_IS_MAT_CONT(npoints->type));
12041205
nimages = npoints->rows + npoints->cols - 1;
12051206

12061207
if( (CV_MAT_TYPE(objectPoints->type) != CV_32FC3 &&
@@ -1221,6 +1222,9 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
12211222
// extract vanishing points in order to obtain initial value for the focal length
12221223
for( i = 0, pos = 0; i < nimages; i++, pos += ni )
12231224
{
1225+
CV_DbgAssert(npoints->data.i);
1226+
CV_DbgAssert(matA && matA->data.db);
1227+
CV_DbgAssert(_b && _b->data.db);
12241228
double* Ap = matA->data.db + i*4;
12251229
double* bp = _b->data.db + i*2;
12261230
ni = npoints->data.i[i];
@@ -1231,6 +1235,7 @@ CV_IMPL void cvInitIntrinsicParams2D( const CvMat* objectPoints,
12311235
cvGetCols( imagePoints, &_m, pos, pos + ni );
12321236

12331237
cvFindHomography( &matM, &_m, &matH );
1238+
CV_DbgAssert(_allH && _allH->data.db);
12341239
memcpy( _allH->data.db + i*9, H, sizeof(H) );
12351240

12361241
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,
38283833

38293834
double y1_ = 0, y2_ = 0, y1y1_ = 0, y1y2_ = 0;
38303835
size_t n = imgpt1.size();
3836+
CV_DbgAssert(n > 0);
38313837

38323838
for( size_t i = 0; i < n; i++ )
38333839
{

modules/dnn/src/layers/convolution_layer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ class ConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl
546546
std::vector<size_t> dims = ieInpNode->get_shape();
547547
CV_Assert(dims.size() == 4 || dims.size() == 5);
548548
std::shared_ptr<ngraph::Node> ieWeights = nodes.size() > 1 ? nodes[1].dynamicCast<InfEngineNgraphNode>()->node : nullptr;
549+
if (nodes.size() > 1)
550+
CV_Assert(ieWeights); // dynamic_cast should not fail
549551
const int inpCn = dims[1];
550552
const int inpGroupCn = nodes.size() > 1 ? ieWeights->get_shape()[1] : blobs[0].size[1];
551553
const int group = inpCn / inpGroupCn;
@@ -653,6 +655,7 @@ class ConvolutionLayerImpl CV_FINAL : public BaseConvolutionLayerImpl
653655
ParallelConv()
654656
: input_(0), weights_(0), output_(0), ngroups_(0), nstripes_(0),
655657
biasvec_(0), reluslope_(0), activ_(0), is1x1_(false), useAVX(false), useAVX2(false), useAVX512(false)
658+
, blk_size_cn(0)
656659
{}
657660

658661
static void run( const Mat& input, Mat& output, const Mat& weights,

modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class OCL4DNNInnerProduct
433433
UMat& top_data);
434434
private:
435435
OCL4DNNInnerProductConfig config_;
436-
int32_t axis_;
436+
//int32_t axis_;
437437
int32_t num_output_;
438438
int32_t M_;
439439
int32_t N_;

modules/flann/include/opencv2/flann/result_set.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ class KNNResultSet : public ResultSet<DistanceType>
160160
DistanceType worst_distance_;
161161

162162
public:
163-
KNNResultSet(int capacity_) : capacity(capacity_), count(0)
163+
KNNResultSet(int capacity_)
164+
: indices(NULL), dists(NULL), capacity(capacity_), count(0), worst_distance_(0)
164165
{
165166
}
166167

@@ -186,6 +187,8 @@ class KNNResultSet : public ResultSet<DistanceType>
186187

187188
void addPoint(DistanceType dist, int index) CV_OVERRIDE
188189
{
190+
CV_DbgAssert(indices);
191+
CV_DbgAssert(dists);
189192
if (dist >= worst_distance_) return;
190193
int i;
191194
for (i = count; i > 0; --i) {

modules/flann/include/opencv2/flann/timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class StartStopTimer
6060
* Constructor.
6161
*/
6262
StartStopTimer()
63+
: startTime(0)
6364
{
6465
reset();
6566
}

modules/highgui/src/window_w32.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ icvSaveWindowPos( const char* name, CvRect rect )
429429

430430
CvRect cvGetWindowRect_W32(const char* name)
431431
{
432+
RECT rect = { 0 };
432433
CvRect result = cvRect(-1, -1, -1, -1);
433434

434435
CV_FUNCNAME( "cvGetWindowRect_W32" );
@@ -443,7 +444,6 @@ CvRect cvGetWindowRect_W32(const char* name)
443444
if (!window)
444445
EXIT; // keep silence here
445446

446-
RECT rect;
447447
GetClientRect(window->hwnd, &rect);
448448
{
449449
POINT pt = {rect.left, rect.top};
@@ -513,7 +513,7 @@ void cvSetModeWindow_W32( const char* name, double prop_value)//Yannick Verdie
513513
if (window->status==CV_WINDOW_NORMAL && prop_value==CV_WINDOW_FULLSCREEN)
514514
{
515515
//save dimension
516-
RECT rect;
516+
RECT rect = { 0 };
517517
GetWindowRect(window->frame, &rect);
518518
CvRect RectCV = cvRect(rect.left, rect.top,rect.right - rect.left, rect.bottom - rect.top);
519519
icvSaveWindowPos(window->name,RectCV );
@@ -1106,7 +1106,7 @@ static void icvScreenToClient( HWND hwnd, RECT* rect )
11061106
static RECT icvCalcWindowRect( CvWindow* window )
11071107
{
11081108
const int gutter = 1;
1109-
RECT crect, trect, rect;
1109+
RECT crect = { 0 }, trect = { 0 } , rect = { 0 };
11101110

11111111
assert(window);
11121112

@@ -1162,7 +1162,7 @@ static bool icvGetBitmapData( CvWindow* window, SIZE* size, int* channels, void*
11621162

11631163
static void icvUpdateWindowPos( CvWindow* window )
11641164
{
1165-
RECT rect;
1165+
RECT rect = { 0 };
11661166
assert(window);
11671167

11681168
if( (window->flags & CV_WINDOW_AUTOSIZE) && window->image )
@@ -1175,7 +1175,7 @@ static void icvUpdateWindowPos( CvWindow* window )
11751175
// toolbar may resize too
11761176
for(i = 0; i < (window->toolbar.toolbar ? 2 : 1); i++)
11771177
{
1178-
RECT rmw, rw = icvCalcWindowRect(window );
1178+
RECT rmw = { 0 }, rw = icvCalcWindowRect(window );
11791179
MoveWindow(window->hwnd, rw.left, rw.top,
11801180
rw.right - rw.left, rw.bottom - rw.top, FALSE);
11811181
GetClientRect(window->hwnd, &rw);
@@ -1362,7 +1362,7 @@ CV_IMPL void cvResizeWindow(const char* name, int width, int height )
13621362

13631363
int i;
13641364
CvWindow* window;
1365-
RECT rmw, rw, rect;
1365+
RECT rmw = { 0 }, rw = { 0 }, rect = { 0 };
13661366

13671367
if( !name )
13681368
CV_ERROR( CV_StsNullPtr, "NULL name" );
@@ -1401,7 +1401,7 @@ CV_IMPL void cvMoveWindow( const char* name, int x, int y )
14011401
__BEGIN__;
14021402

14031403
CvWindow* window;
1404-
RECT rect;
1404+
RECT rect = { 0 };
14051405

14061406
if( !name )
14071407
CV_ERROR( CV_StsNullPtr, "NULL name" );
@@ -1441,7 +1441,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
14411441
if( !(window->flags & CV_WINDOW_AUTOSIZE) )
14421442
{
14431443
MINMAXINFO* minmax = (MINMAXINFO*)lParam;
1444-
RECT rect;
1444+
RECT rect = { 0 };
14451445
LRESULT retval = DefWindowProc(hwnd, uMsg, wParam, lParam);
14461446

14471447
minmax->ptMinTrackSize.y = 100;
@@ -1464,7 +1464,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
14641464
// Update the toolbar pos/size
14651465
if(window->toolbar.toolbar)
14661466
{
1467-
RECT rect;
1467+
RECT rect = { 0 };
14681468
GetWindowRect(window->toolbar.toolbar, &rect);
14691469
MoveWindow(window->toolbar.toolbar, 0, 0, pos->cx, rect.bottom - rect.top, TRUE);
14701470
}
@@ -1480,7 +1480,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
14801480
// Snap window to screen edges with multi-monitor support. // Adi Shavit
14811481
LPWINDOWPOS pos = (LPWINDOWPOS)lParam;
14821482

1483-
RECT rect;
1483+
RECT rect = { 0 };
14841484
GetWindowRect(window->frame, &rect);
14851485

14861486
HMONITOR hMonitor;
@@ -1531,7 +1531,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
15311531
pt.y = GET_Y_LPARAM( lParam );
15321532
::ScreenToClient(hwnd, &pt); // Convert screen coordinates to client coordinates.
15331533

1534-
RECT rect;
1534+
RECT rect = { 0 };
15351535
GetClientRect( window->hwnd, &rect );
15361536

15371537
SIZE size = {0,0};
@@ -1558,7 +1558,7 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
15581558

15591559
case WM_ERASEBKGND:
15601560
{
1561-
RECT cr, tr, wrc;
1561+
RECT cr = { 0 }, tr = { 0 }, wrc = { 0 };
15621562
HRGN rgn, rgn1, rgn2;
15631563
int ret;
15641564
HDC hdc = (HDC)wParam;
@@ -1738,7 +1738,7 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
17381738
window->on_mouse( event, pt.x, pt.y, flags, window->on_mouse_param );
17391739
} else {
17401740
// Full window is displayed using different size. Scale coordinates to match underlying positions.
1741-
RECT rect;
1741+
RECT rect = { 0 };
17421742
SIZE size = {0, 0};
17431743

17441744
GetClientRect( window->hwnd, &rect );
@@ -1798,7 +1798,7 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
17981798
}
17991799
else
18001800
{
1801-
RECT rect;
1801+
RECT rect = { 0 };
18021802
GetClientRect(window->hwnd, &rect);
18031803
StretchBlt( hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
18041804
window->dc, 0, 0, size.cx, size.cy, SRCCOPY );
@@ -1955,7 +1955,7 @@ static LRESULT CALLBACK HGToolbarProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPAR
19551955

19561956
for( ; trackbar != 0; trackbar = trackbar->next )
19571957
{
1958-
RECT rect;
1958+
RECT rect = { 0 };
19591959
SendMessage(window->toolbar.toolbar, TB_GETITEMRECT,
19601960
(WPARAM)trackbar->id, (LPARAM)&rect);
19611961
MoveWindow(trackbar->hwnd, rect.left + HG_BUDDY_WIDTH, rect.top,
@@ -2180,7 +2180,7 @@ icvCreateTrackbar( const char* trackbar_name, const char* window_name,
21802180
{
21812181
TBBUTTON tbs = {};
21822182
TBBUTTONINFO tbis = {};
2183-
RECT rect;
2183+
RECT rect = { 0 };
21842184
int bcount;
21852185
int len = (int)strlen( trackbar_name );
21862186

modules/objdetect/src/cascadedetect_convert.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ struct HaarClassifier
107107

108108
struct HaarStageClassifier
109109
{
110+
HaarStageClassifier() : threshold(0) {}
111+
110112
double threshold;
111113
std::vector<HaarClassifier> weaks;
112114
};

0 commit comments

Comments
 (0)