Skip to content

Commit a065e4b

Browse files
committed
Merge pull request opencv#8769 from mshabunin:kw-fixes
2 parents 55ee8b2 + b04ed59 commit a065e4b

File tree

16 files changed

+170
-100
lines changed

16 files changed

+170
-100
lines changed

modules/core/include/opencv2/core/base.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,17 @@ CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const ch
381381
#define CV_Func ""
382382
#endif
383383

384+
#ifdef CV_STATIC_ANALYSIS
385+
// In practice, some macro are not processed correctly (noreturn is not detected).
386+
// We need to use simplified definition for them.
387+
#define CV_Error(...) do { abort(); } while (0)
388+
#define CV_Error_(...) do { abort(); } while (0)
389+
#define CV_Assert(cond) do { if (!(cond)) abort(); } while (0)
390+
#define CV_ErrorNoReturn(...) do { abort(); } while (0)
391+
#define CV_ErrorNoReturn_(...) do { abort(); } while (0)
392+
393+
#else // CV_STATIC_ANALYSIS
394+
384395
/** @brief Call the error handler.
385396
386397
Currently, the error handler prints the error code and the error message to the standard
@@ -421,6 +432,8 @@ configurations while CV_DbgAssert is only retained in the Debug configuration.
421432
/** same as CV_Error_(code,args), but does not return */
422433
#define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
423434

435+
#endif // CV_STATIC_ANALYSIS
436+
424437
/** replaced with CV_Assert(expr) in Debug configuration */
425438
#ifdef _DEBUG
426439
# define CV_DbgAssert(expr) CV_Assert(expr)

modules/core/include/opencv2/core/cvdef.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ Cv64suf;
302302
# define MAX(a,b) ((a) < (b) ? (b) : (a))
303303
#endif
304304

305+
/****************************************************************************************\
306+
* static analysys *
307+
\****************************************************************************************/
308+
309+
// In practice, some macro are not processed correctly (noreturn is not detected).
310+
// We need to use simplified definition for them.
311+
#ifndef CV_STATIC_ANALYSIS
312+
# if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__)
313+
# define CV_STATIC_ANALYSIS
314+
# endif
315+
#endif
316+
305317
/****************************************************************************************\
306318
* exchange-add operation for atomic operations on reference counters *
307319
\****************************************************************************************/

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
@@ -3739,7 +3739,7 @@ size_t UMat::step1(int i) const
37393739
inline
37403740
bool UMat::empty() const
37413741
{
3742-
return u == 0 || total() == 0;
3742+
return u == 0 || total() == 0 || dims == 0;
37433743
}
37443744

37453745
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())

0 commit comments

Comments
 (0)