From c5e9d1adaefd21b98355620fc019a7f7c92ef2c1 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 18 May 2017 15:00:17 +0300 Subject: [PATCH] macro for static analysis tools --- modules/core/include/opencv2/core/base.hpp | 13 +++++++++++++ modules/core/include/opencv2/core/cvdef.h | 12 ++++++++++++ modules/imgproc/src/thresh.cpp | 12 ++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 3334ebe769..a445599946 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -381,6 +381,17 @@ CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const ch #define CV_Func "" #endif +#ifdef CV_STATIC_ANALYSIS +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#define CV_Error(...) do { abort(); } while (0) +#define CV_Error_(...) do { abort(); } while (0) +#define CV_Assert(cond) do { if (!(cond)) abort(); } while (0) +#define CV_ErrorNoReturn(...) do { abort(); } while (0) +#define CV_ErrorNoReturn_(...) do { abort(); } while (0) + +#else // CV_STATIC_ANALYSIS + /** @brief Call the error handler. 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. /** same as CV_Error_(code,args), but does not return */ #define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ ) +#endif // CV_STATIC_ANALYSIS + /** replaced with CV_Assert(expr) in Debug configuration */ #ifdef _DEBUG # define CV_DbgAssert(expr) CV_Assert(expr) diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index a0c3438116..47b2c12637 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -302,6 +302,18 @@ Cv64suf; # define MAX(a,b) ((a) < (b) ? (b) : (a)) #endif +/****************************************************************************************\ +* static analysys * +\****************************************************************************************/ + +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#ifndef CV_STATIC_ANALYSIS +# if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__) +# define CV_STATIC_ANALYSIS +# endif +#endif + /****************************************************************************************\ * exchange-add operation for atomic operations on reference counters * \****************************************************************************************/ diff --git a/modules/imgproc/src/thresh.cpp b/modules/imgproc/src/thresh.cpp index bd2b73c0bb..df9de3c556 100644 --- a/modules/imgproc/src/thresh.cpp +++ b/modules/imgproc/src/thresh.cpp @@ -463,7 +463,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type ) } break; default: - return CV_Error( CV_StsBadArg, "" ); + CV_Error( CV_StsBadArg, "" ); return; } } else @@ -517,7 +517,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type ) } break; default: - return CV_Error( CV_StsBadArg, "" ); + CV_Error( CV_StsBadArg, "" ); return; } } } @@ -698,7 +698,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) } break; default: - return CV_Error( CV_StsBadArg, "" ); + CV_Error( CV_StsBadArg, "" ); return; } } else @@ -752,7 +752,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) } break; default: - return CV_Error( CV_StsBadArg, "" ); + CV_Error( CV_StsBadArg, "" ); return; } } } @@ -893,7 +893,7 @@ thresh_64f(const Mat& _src, Mat& _dst, double thresh, double maxval, int type) } break; default: - return CV_Error(CV_StsBadArg, ""); + CV_Error(CV_StsBadArg, ""); return; } } else @@ -952,7 +952,7 @@ thresh_64f(const Mat& _src, Mat& _dst, double thresh, double maxval, int type) } break; default: - return CV_Error(CV_StsBadArg, ""); + CV_Error(CV_StsBadArg, ""); return; } } }