From dd5976162b58cc9f78a3abac42da283c0778162f Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 24 Feb 2021 20:31:00 +0300 Subject: [PATCH] Fixed several issues found by static analysis --- modules/calib3d/src/sqpnp.hpp | 1 + modules/dnn/src/layers/elementwise_layers.cpp | 21 +++++++------------ modules/dnn/src/layers/pooling_layer.cpp | 2 +- modules/dnn/src/model.cpp | 1 + modules/videoio/src/cap_msmf.cpp | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/modules/calib3d/src/sqpnp.hpp b/modules/calib3d/src/sqpnp.hpp index f8136324c9..97c10e34e7 100644 --- a/modules/calib3d/src/sqpnp.hpp +++ b/modules/calib3d/src/sqpnp.hpp @@ -72,6 +72,7 @@ private: cv::Matx r_hat; cv::Matx t; double sq_error; + SQPSolution() : sq_error(0) {} }; /* diff --git a/modules/dnn/src/layers/elementwise_layers.cpp b/modules/dnn/src/layers/elementwise_layers.cpp index 23d4c50521..c57b833b85 100644 --- a/modules/dnn/src/layers/elementwise_layers.cpp +++ b/modules/dnn/src/layers/elementwise_layers.cpp @@ -1408,29 +1408,24 @@ struct ExpFunctor : public BaseFunctor ExpFunctor(float base_ = -1.f, float scale_ = 1.f, float shift_ = 0.f) : base(base_), scale(scale_), shift(shift_) - { - CV_Check(base, base == -1.f || base > 0.f, "Unsupported 'base' value"); - } - - bool supportBackend(int backendId, int targetId) - { - return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_CUDA || - backendId == DNN_BACKEND_HALIDE || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; - } - - void finalize() { // For base > 0 : // y = base^(scale * input + shift) // ln(y) = ln(base)*(scale * input + shift) // y = exp((ln(base)*scale) * input + (ln(base)*shift)) // y = exp(normalized_scale * input + normalized_shift) - - float ln_base = (base == -1.f) ? 1.f : log(base); + CV_Check(base, base == -1.f || base > 0.f, "Unsupported 'base' value"); + const float ln_base = (base == -1.f) ? 1.f : log(base); normScale = scale * ln_base; normShift = shift * ln_base; } + bool supportBackend(int backendId, int targetId) + { + return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_CUDA || + backendId == DNN_BACKEND_HALIDE || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; + } + void apply(const float* srcptr, float* dstptr, int len, size_t planeSize, int cn0, int cn1) const { float a = normScale, b = normShift; diff --git a/modules/dnn/src/layers/pooling_layer.cpp b/modules/dnn/src/layers/pooling_layer.cpp index ac78c5eeab..b2fe0a3994 100644 --- a/modules/dnn/src/layers/pooling_layer.cpp +++ b/modules/dnn/src/layers/pooling_layer.cpp @@ -917,7 +917,7 @@ public: if (max_elem!=last) { dstData[x0] = *max_elem; - if( compMaxIdx ) + if( compMaxIdx && dstMaskData ) { dstMaskData[x0] = std::distance(first, max_elem); } diff --git a/modules/dnn/src/model.cpp b/modules/dnn/src/model.cpp index fae235a3b5..0af8223a7f 100644 --- a/modules/dnn/src/model.cpp +++ b/modules/dnn/src/model.cpp @@ -1213,6 +1213,7 @@ struct TextDetectionModel_DB_Impl : public TextDetectionModel_Impl { double area = contourArea(inPoly); double length = arcLength(inPoly, true); + CV_Assert(length > FLT_EPSILON); double distance = area * unclipRatio / length; size_t numPoints = inPoly.size(); diff --git a/modules/videoio/src/cap_msmf.cpp b/modules/videoio/src/cap_msmf.cpp index a1d4a28131..6b870a24d1 100644 --- a/modules/videoio/src/cap_msmf.cpp +++ b/modules/videoio/src/cap_msmf.cpp @@ -314,7 +314,7 @@ class SourceReaderCB : public IMFSourceReaderCallback { public: SourceReaderCB() : - m_nRefCount(0), m_hEvent(CreateEvent(NULL, FALSE, FALSE, NULL)), m_bEOS(FALSE), m_hrStatus(S_OK), m_reader(NULL), m_dwStreamIndex(0) + m_nRefCount(0), m_hEvent(CreateEvent(NULL, FALSE, FALSE, NULL)), m_bEOS(FALSE), m_hrStatus(S_OK), m_reader(NULL), m_dwStreamIndex(0), m_lastSampleTimestamp(0) { }