(3.4) Fixed several issues found by static analysis
authorMaksim Shabunin <maksim.shabunin@intel.com>
Wed, 15 Dec 2021 09:49:13 +0000 (12:49 +0300)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 16 Dec 2021 17:02:58 +0000 (17:02 +0000)
original commit: a079c2eb7cb74b4520c69b6f6c2ea79c7d410871

modules/dnn/src/onnx/onnx_importer.cpp
modules/objdetect/src/qrcode_encoder.cpp

index 052b1b8..df404a9 100644 (file)
@@ -1821,7 +1821,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);
index ae15c64..2b363b6 100644 (file)
@@ -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;