Skip to content

Commit b04ed59

Browse files
committed
Fixed several issues found by static analysis in core module
1 parent c5e9d1a commit b04ed59

File tree

13 files changed

+139
-94
lines changed

13 files changed

+139
-94
lines changed

modules/core/include/opencv2/core/mat.inl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ size_t Mat::step1(int i) const
872872
inline
873873
bool Mat::empty() const
874874
{
875-
return data == 0 || total() == 0;
875+
return data == 0 || total() == 0 || dims == 0;
876876
}
877877

878878
inline
@@ -3730,7 +3730,7 @@ size_t UMat::step1(int i) const
37303730
inline
37313731
bool UMat::empty() const
37323732
{
3733-
return u == 0 || total() == 0;
3733+
return u == 0 || total() == 0 || dims == 0;
37343734
}
37353735

37363736
inline

modules/core/include/opencv2/core/types.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b)
10401040
template<typename _Tp> static inline
10411041
Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b)
10421042
{
1043-
return (a = a / b);
1043+
a = a / b;
1044+
return a;
10441045
}
10451046

10461047
template<typename _Tp> static inline

modules/core/src/arithm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
523523
float usrdata_f[3];
524524
int i, n = oclop == OCL_OP_MUL_SCALE || oclop == OCL_OP_DIV_SCALE ||
525525
oclop == OCL_OP_RDIV_SCALE || oclop == OCL_OP_RECIP_SCALE ? 1 : oclop == OCL_OP_ADDW ? 3 : 0;
526-
if( n > 0 && wdepth == CV_32F )
526+
if( usrdata && n > 0 && wdepth == CV_32F )
527527
{
528528
for( i = 0; i < n; i++ )
529529
usrdata_f[i] = (float)usrdata_d[i];

modules/core/src/array.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ cvCreateSparseMat( int dims, const int* sizes, int type )
545545
if( pix_size == 0 )
546546
CV_Error( CV_StsUnsupportedFormat, "invalid array data type" );
547547

548-
if( dims <= 0 || dims > CV_MAX_DIM_HEAP )
548+
if( dims <= 0 || dims > CV_MAX_DIM )
549549
CV_Error( CV_StsOutOfRange, "bad number of dimensions" );
550550

551551
if( !sizes )
@@ -1839,6 +1839,7 @@ cvPtr2D( const CvArr* arr, int y, int x, int* _type )
18391839
}
18401840
else if( CV_IS_SPARSE_MAT( arr ))
18411841
{
1842+
CV_Assert(((CvSparseMat*)arr)->dims == 2);
18421843
int idx[] = { y, x };
18431844
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, _type, 1, 0 );
18441845
}

modules/core/src/copy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ Mat& Mat::operator = (const Scalar& s)
448448
for( size_t j = 0; j < elsize; j += blockSize )
449449
{
450450
size_t sz = MIN(blockSize, elsize - j);
451+
CV_Assert(sz <= sizeof(scalar));
451452
memcpy( dptr + j, scalar, sz );
452453
}
453454
}

modules/core/src/matrix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5786,10 +5786,10 @@ void minMaxLoc( const SparseMat& src, double* _minval, double* _maxval, int* _mi
57865786
else
57875787
CV_Error( CV_StsUnsupportedFormat, "Only 32f and 64f are supported" );
57885788

5789-
if( _minidx )
5789+
if( _minidx && minidx )
57905790
for( i = 0; i < d; i++ )
57915791
_minidx[i] = minidx[i];
5792-
if( _maxidx )
5792+
if( _maxidx && maxidx )
57935793
for( i = 0; i < d; i++ )
57945794
_maxidx[i] = maxidx[i];
57955795
}
@@ -5898,7 +5898,7 @@ _IplImage::_IplImage(const cv::Mat& m)
58985898

58995899
CvSparseMat* cvCreateSparseMat(const cv::SparseMat& sm)
59005900
{
5901-
if( !sm.hdr )
5901+
if( !sm.hdr || sm.hdr->dims > (int)cv::SparseMat::MAX_DIM)
59025902
return 0;
59035903

59045904
CvSparseMat* m = cvCreateSparseMat(sm.hdr->dims, sm.hdr->size, sm.type());

modules/core/src/ocl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ static cl_device_id selectOpenCLDevice()
12041204
if (!configuration)
12051205
return NULL; // suppress messages on stderr
12061206

1207-
std::cerr << "ERROR: Requested OpenCL device not found, check configuration: " << (configuration == NULL ? "" : configuration) << std::endl
1207+
std::cerr << "ERROR: Requested OpenCL device not found, check configuration: " << configuration << std::endl
12081208
<< " Platform: " << (platform.length() == 0 ? "any" : platform) << std::endl
12091209
<< " Device types: ";
12101210
for (size_t t = 0; t < deviceTypes.size(); t++)

modules/core/src/out.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace cv
103103
}
104104
else
105105
{
106-
sprintf(floatFormat, "%%.%dg", std::min(precision, 20));
106+
snprintf(floatFormat, 8, "%%.%dg", std::min(precision, 20));
107107
}
108108

109109
switch(mtx.depth())

modules/core/src/parallel_pthreads.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ class ForThread
141141
pthread_t m_posix_thread;
142142
pthread_mutex_t m_thread_mutex;
143143
pthread_cond_t m_cond_thread_task;
144-
bool m_task_start;
144+
volatile bool m_task_start;
145145

146146
ThreadManager* m_parent;
147-
ForThreadState m_state;
147+
volatile ForThreadState m_state;
148148
size_t m_id;
149149
};
150150

0 commit comments

Comments
 (0)