Skip to content

Commit c5e9d1a

Browse files
alalekmshabunin
authored andcommitted
macro for static analysis tools
1 parent 0bc30d3 commit c5e9d1a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
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/imgproc/src/thresh.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
463463
}
464464
break;
465465
default:
466-
return CV_Error( CV_StsBadArg, "" );
466+
CV_Error( CV_StsBadArg, "" ); return;
467467
}
468468
}
469469
else
@@ -517,7 +517,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
517517
}
518518
break;
519519
default:
520-
return CV_Error( CV_StsBadArg, "" );
520+
CV_Error( CV_StsBadArg, "" ); return;
521521
}
522522
}
523523
}
@@ -698,7 +698,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
698698
}
699699
break;
700700
default:
701-
return CV_Error( CV_StsBadArg, "" );
701+
CV_Error( CV_StsBadArg, "" ); return;
702702
}
703703
}
704704
else
@@ -752,7 +752,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
752752
}
753753
break;
754754
default:
755-
return CV_Error( CV_StsBadArg, "" );
755+
CV_Error( CV_StsBadArg, "" ); return;
756756
}
757757
}
758758
}
@@ -893,7 +893,7 @@ thresh_64f(const Mat& _src, Mat& _dst, double thresh, double maxval, int type)
893893
}
894894
break;
895895
default:
896-
return CV_Error(CV_StsBadArg, "");
896+
CV_Error(CV_StsBadArg, ""); return;
897897
}
898898
}
899899
else
@@ -952,7 +952,7 @@ thresh_64f(const Mat& _src, Mat& _dst, double thresh, double maxval, int type)
952952
}
953953
break;
954954
default:
955-
return CV_Error(CV_StsBadArg, "");
955+
CV_Error(CV_StsBadArg, ""); return;
956956
}
957957
}
958958
}

0 commit comments

Comments
 (0)