From a079c2eb7cb74b4520c69b6f6c2ea79c7d410871 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 15 Dec 2021 12:49:13 +0300 Subject: [PATCH] Fixed several issues found by static analysis --- modules/dnn/src/int8layers/eltwise_layer.cpp | 5 +++-- modules/dnn/src/onnx/onnx_importer.cpp | 4 +++- modules/objdetect/src/face_detect.cpp | 1 + modules/objdetect/src/face_recognize.cpp | 4 ++-- modules/objdetect/src/qrcode_encoder.cpp | 2 ++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/dnn/src/int8layers/eltwise_layer.cpp b/modules/dnn/src/int8layers/eltwise_layer.cpp index be7a32b1ef..a522bc9031 100644 --- a/modules/dnn/src/int8layers/eltwise_layer.cpp +++ b/modules/dnn/src/int8layers/eltwise_layer.cpp @@ -238,7 +238,7 @@ public: EltwiseInvoker(EltwiseLayerInt8Impl& self_) : self(self_) - , nsrcs(0), dst(0), buf(0), nstripes(0), activ(0), channels(0) + , nsrcs(0), dst(0), buf(0), nstripes(0), activLUT(0), activ(0), channels(0) , planeSize(0), offset(0) {} @@ -345,7 +345,8 @@ public: int8_t* dstptr0 = dst->ptr(); float* bufptr0 = buf->ptr(); int blockSize0 = 1 << 12; - + CV_Assert(op != PROD || zeropointsptr); + CV_Assert((op != PROD && op != SUM) || coeffsptr); for (size_t ofs = stripeStart; ofs < stripeEnd; ) { int sampleIdx = (int)(ofs / planeSize); diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 85c4479c6f..8edc38979e 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -2023,7 +2023,9 @@ void ONNXImporter::parseUnsqueeze(LayerParams& layerParams, const opencv_onnx::N } CV_Assert(axes.getIntValue(axes.size()-1) <= dims.size()); for (int j = 0; j < axes.size(); j++) { - dims.insert(dims.begin() + axes.getIntValue(j), 1); + const int idx = axes.getIntValue(j); + CV_Assert(idx <= dims.size()); + dims.insert(dims.begin() + idx, 1); } Mat out = input.reshape(0, dims); diff --git a/modules/objdetect/src/face_detect.cpp b/modules/objdetect/src/face_detect.cpp index 4095745b7e..a9ca2d8957 100644 --- a/modules/objdetect/src/face_detect.cpp +++ b/modules/objdetect/src/face_detect.cpp @@ -142,6 +142,7 @@ private: {64.0f, 96.0f}, {128.0f, 192.0f, 256.0f} }; + CV_Assert(min_sizes.size() == feature_map_sizes.size()); // just to keep vectors in sync const std::vector steps = { 8, 16, 32, 64 }; // Generate priors diff --git a/modules/objdetect/src/face_recognize.cpp b/modules/objdetect/src/face_recognize.cpp index 6550a13b4b..66271068b2 100644 --- a/modules/objdetect/src/face_recognize.cpp +++ b/modules/objdetect/src/face_recognize.cpp @@ -45,8 +45,8 @@ public: double match(InputArray _face_feature1, InputArray _face_feature2, int dis_type) const override { Mat face_feature1 = _face_feature1.getMat(), face_feature2 = _face_feature2.getMat(); - face_feature1 /= norm(face_feature1); - face_feature2 /= norm(face_feature2); + normalize(face_feature1, face_feature1); + normalize(face_feature2, face_feature2); if(dis_type == DisType::FR_COSINE){ return sum(face_feature1.mul(face_feature2))[0]; diff --git a/modules/objdetect/src/qrcode_encoder.cpp b/modules/objdetect/src/qrcode_encoder.cpp index ae15c64f42..2b363b607d 100644 --- a/modules/objdetect/src/qrcode_encoder.cpp +++ b/modules/objdetect/src/qrcode_encoder.cpp @@ -881,6 +881,8 @@ void QRCodeEncoderImpl::findAutoMaskType() total_modules += 1; } } + if (total_modules == 0) + continue; // TODO: refactor, extract functions to reduce complexity int modules_percent = dark_modules * 100 / total_modules; int lower_bound = 45; int upper_bound = 55; -- GitLab