From: Maksim Shabunin Date: Mon, 25 Dec 2017 13:57:40 +0000 (+0300) Subject: Fixed several warnings produced by clang 6 and static analyzers X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~176^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b87c4b96a1c1025099cf0dd1cfd6b09139202c6;p=platform%2Fupstream%2Fopencv.git Fixed several warnings produced by clang 6 and static analyzers --- diff --git a/3rdparty/protobuf/CMakeLists.txt b/3rdparty/protobuf/CMakeLists.txt index 4e556eb..dee7c0c 100644 --- a/3rdparty/protobuf/CMakeLists.txt +++ b/3rdparty/protobuf/CMakeLists.txt @@ -20,6 +20,7 @@ else() -Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo -Wundef -Wtautological-undefined-compare -Wignored-qualifiers -Wextra -Wunused-function -Wunused-const-variable -Wshorten-64-to-32 -Wno-invalid-offsetof + -Wenum-compare-switch ) endif() if(CV_ICC) diff --git a/modules/calib3d/src/fisheye.cpp b/modules/calib3d/src/fisheye.cpp index 05c22ac..3ed9ba4 100644 --- a/modules/calib3d/src/fisheye.cpp +++ b/modules/calib3d/src/fisheye.cpp @@ -762,7 +762,7 @@ double cv::fisheye::calibrate(InputArrayOfArrays objectPoints, InputArrayOfArray //-------------------------------Optimization - for(int iter = 0; iter <= std::numeric_limits::max(); ++iter) + for(int iter = 0; iter < std::numeric_limits::max(); ++iter) { if ((criteria.type == 1 && iter >= criteria.maxCount) || (criteria.type == 2 && change <= criteria.epsilon) || diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 0519092..d973268 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -409,13 +409,14 @@ CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const ch #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_Error_( code, args ) do { cv::format args; abort(); } while (0) #define CV_ErrorNoReturn(...) do { abort(); } while (0) #define CV_ErrorNoReturn_(...) do { abort(); } while (0) +#define CV_Assert_1( expr ) do { if (!(expr)) abort(); } while (0) #else // CV_STATIC_ANALYSIS @@ -445,17 +446,16 @@ for example: */ #define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ ) -/** @brief Checks a condition at runtime and throws exception if it fails - -The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros -raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release -configurations while CV_DbgAssert is only retained in the Debug configuration. -*/ +/** same as CV_Error(code,msg), but does not return */ +#define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ ) -#define CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N -#define CV_VA_NUM_ARGS(...) CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) +/** 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__ ) #define CV_Assert_1( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ) + +#endif // CV_STATIC_ANALYSIS + #define CV_Assert_2( expr1, expr2 ) CV_Assert_1(expr1); CV_Assert_1(expr2) #define CV_Assert_3( expr1, expr2, expr3 ) CV_Assert_2(expr1, expr2); CV_Assert_1(expr3) #define CV_Assert_4( expr1, expr2, expr3, expr4 ) CV_Assert_3(expr1, expr2, expr3); CV_Assert_1(expr4) @@ -466,15 +466,16 @@ configurations while CV_DbgAssert is only retained in the Debug configuration. #define CV_Assert_9( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ) CV_Assert_8(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8 ); CV_Assert_1(expr9) #define CV_Assert_10( expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9, expr10 ) CV_Assert_9(expr1, expr2, expr3, expr4, expr5, expr6, expr7, expr8, expr9 ); CV_Assert_1(expr10) -#define CV_Assert(...) CVAUX_CONCAT(CV_Assert_, CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__) - -/** same as CV_Error(code,msg), but does not return */ -#define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ ) +#define CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N +#define CV_VA_NUM_ARGS(...) CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) -/** 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__ ) +/** @brief Checks a condition at runtime and throws exception if it fails -#endif // CV_STATIC_ANALYSIS +The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros +raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release +configurations while CV_DbgAssert is only retained in the Debug configuration. +*/ +#define CV_Assert(...) do { CVAUX_CONCAT(CV_Assert_, CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__); } while(0) /** replaced with CV_Assert(expr) in Debug configuration */ #ifdef _DEBUG diff --git a/modules/core/src/array.cpp b/modules/core/src/array.cpp index 782810c..d200842 100644 --- a/modules/core/src/array.cpp +++ b/modules/core/src/array.cpp @@ -3125,6 +3125,7 @@ cvCloneImage( const IplImage* src ) dst = (IplImage*)cvAlloc( sizeof(*dst)); memcpy( dst, src, sizeof(*src)); + dst->nSize = sizeof(IplImage); dst->imageData = dst->imageDataOrigin = 0; dst->roi = 0; diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index e2a0222..d7374e2 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -2135,13 +2135,38 @@ static bool ocl_dft_cols(InputArray _src, OutputArray _dst, int nonzero_cols, in return plan->enqueueTransform(_src, _dst, nonzero_cols, flags, fftType, false); } +inline FftType determineFFTType(bool real_input, bool complex_input, bool real_output, bool complex_output, bool inv) +{ + // output format is not specified + if (!real_output && !complex_output) + complex_output = true; + + // input or output format is ambiguous + if (real_input == complex_input || real_output == complex_output) + CV_Error(Error::StsBadArg, "Invalid FFT input or output format"); + + FftType result = real_input ? (real_output ? R2R : R2C) : (real_output ? C2R : C2C); + + // Forward Complex to CCS not supported + if (result == C2R && !inv) + result = C2C; + + // Inverse CCS to Complex not supported + if (result == R2C && inv) + result = R2R; + + return result; +} + static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_rows) { int type = _src.type(), cn = CV_MAT_CN(type), depth = CV_MAT_DEPTH(type); Size ssize = _src.size(); bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0; - if ( !((cn == 1 || cn == 2) && (depth == CV_32F || (depth == CV_64F && doubleSupport))) ) + if (!(cn == 1 || cn == 2) + || !(depth == CV_32F || (depth == CV_64F && doubleSupport)) + || ((flags & DFT_REAL_OUTPUT) && (flags & DFT_COMPLEX_OUTPUT))) return false; // if is not a multiplication of prime numbers { 2, 3, 5 } @@ -2149,34 +2174,14 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro return false; UMat src = _src.getUMat(); - int complex_input = cn == 2 ? 1 : 0; - int complex_output = (flags & DFT_COMPLEX_OUTPUT) != 0; - int real_input = cn == 1 ? 1 : 0; - int real_output = (flags & DFT_REAL_OUTPUT) != 0; bool inv = (flags & DFT_INVERSE) != 0 ? 1 : 0; if( nonzero_rows <= 0 || nonzero_rows > _src.rows() ) nonzero_rows = _src.rows(); bool is1d = (flags & DFT_ROWS) != 0 || nonzero_rows == 1; - // if output format is not specified - if (complex_output + real_output == 0) - { - if (real_input) - real_output = 1; - else - complex_output = 1; - } - - FftType fftType = (FftType)(complex_input << 0 | complex_output << 1); - - // Forward Complex to CCS not supported - if (fftType == C2R && !inv) - fftType = C2C; - - // Inverse CCS to Complex not supported - if (fftType == R2C && inv) - fftType = R2R; + FftType fftType = determineFFTType(cn == 1, cn == 2, + (flags & DFT_REAL_OUTPUT) != 0, (flags & DFT_COMPLEX_OUTPUT) != 0, inv); UMat output; if (fftType == C2C || fftType == R2C) @@ -2200,51 +2205,38 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro } } + bool result = false; if (!inv) { - if (!ocl_dft_rows(src, output, nonzero_rows, flags, fftType)) - return false; - + int nonzero_cols = fftType == R2R ? output.cols/2 + 1 : output.cols; + result = ocl_dft_rows(src, output, nonzero_rows, flags, fftType); if (!is1d) - { - int nonzero_cols = fftType == R2R ? output.cols/2 + 1 : output.cols; - if (!ocl_dft_cols(output, _dst, nonzero_cols, flags, fftType)) - return false; - } + result = result && ocl_dft_cols(output, _dst, nonzero_cols, flags, fftType); } else { if (fftType == C2C) { // complex output - if (!ocl_dft_rows(src, output, nonzero_rows, flags, fftType)) - return false; - + result = ocl_dft_rows(src, output, nonzero_rows, flags, fftType); if (!is1d) - { - if (!ocl_dft_cols(output, output, output.cols, flags, fftType)) - return false; - } + result = result && ocl_dft_cols(output, output, output.cols, flags, fftType); } else { if (is1d) { - if (!ocl_dft_rows(src, output, nonzero_rows, flags, fftType)) - return false; + result = ocl_dft_rows(src, output, nonzero_rows, flags, fftType); } else { int nonzero_cols = src.cols/2 + 1; - if (!ocl_dft_cols(src, output, nonzero_cols, flags, fftType)) - return false; - - if (!ocl_dft_rows(output, _dst, nonzero_rows, flags, fftType)) - return false; + result = ocl_dft_cols(src, output, nonzero_cols, flags, fftType); + result = result && ocl_dft_rows(output, _dst, nonzero_rows, flags, fftType); } } } - return true; + return result; } } // namespace cv; diff --git a/modules/features2d/src/agast.cpp b/modules/features2d/src/agast.cpp index ee14d06..e77d556 100644 --- a/modules/features2d/src/agast.cpp +++ b/modules/features2d/src/agast.cpp @@ -8066,7 +8066,6 @@ void AGAST(InputArray _img, std::vector& keypoints, int threshold, boo size_t lastRowCorner_ind = 0, next_lastRowCorner_ind = 0; std::vector nmsFlags; - std::vector::iterator currCorner_nms; std::vector::const_iterator currCorner; currCorner = kpts.begin(); diff --git a/modules/imgcodecs/src/exif.cpp b/modules/imgcodecs/src/exif.cpp index ade6cef..6f19dd0 100644 --- a/modules/imgcodecs/src/exif.cpp +++ b/modules/imgcodecs/src/exif.cpp @@ -480,7 +480,6 @@ uint32_t ExifReader::getU32(const size_t offset) const */ u_rational_t ExifReader::getURational(const size_t offset) const { - u_rational_t result; uint32_t numerator = getU32( offset ); uint32_t denominator = getU32( offset + 4 ); diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index d08b08c..8e2a5e6 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -289,7 +289,7 @@ static bool ipp_Deriv(InputArray _src, OutputArray _dst, int dx, int dy, int ksi } IppiMaskSize maskSize = ippiGetMaskSize(ksize, ksize); - if(maskSize < 0) + if((int)maskSize < 0) return false; #if IPP_VERSION_X100 <= 201703 @@ -299,7 +299,7 @@ static bool ipp_Deriv(InputArray _src, OutputArray _dst, int dx, int dy, int ksi #endif IwiDerivativeType derivType = ippiGetDerivType(dx, dy, (useScharr)?false:true); - if(derivType < 0) + if((int)derivType < 0) return false; // Acquire data and begin processing @@ -728,7 +728,7 @@ static bool ipp_Laplacian(InputArray _src, OutputArray _dst, int ksize, double s useScale = true; IppiMaskSize maskSize = ippiGetMaskSize(ksize, ksize); - if(maskSize < 0) + if((int)maskSize < 0) return false; // Acquire data and begin processing diff --git a/modules/imgproc/src/morph.cpp b/modules/imgproc/src/morph.cpp index a8bdb1b..27c7db7 100644 --- a/modules/imgproc/src/morph.cpp +++ b/modules/imgproc/src/morph.cpp @@ -1181,7 +1181,7 @@ static bool ippMorph(int op, int src_type, int dst_type, CV_UNUSED(isSubmatrix); - if(morphType < 0) + if((int)morphType < 0) return false; if(iterations > 1 && morphType != iwiMorphErode && morphType != iwiMorphDilate) diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index 6b03c44..fb0de06 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -3577,7 +3577,7 @@ static bool ipp_resize(const uchar * src_data, size_t src_step, int src_width, i IppDataType ippDataType = ippiGetDataType(depth); IppiInterpolationType ippInter = ippiGetInterpolation(interpolation); - if(ippInter < 0) + if((int)ippInter < 0) return false; // Resize which doesn't match OpenCV exactly