From 7e7bb3027ca313a74803c28edd8fedb5080de987 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Mon, 16 Mar 2020 15:49:51 +0300 Subject: [PATCH] Fixs several problems found by static analysis --- modules/calib3d/src/chessboard.cpp | 4 +++- modules/core/src/persistence.cpp | 1 + modules/features2d/src/kaze/AKAZEFeatures.cpp | 1 + modules/objdetect/src/qrcode.cpp | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/calib3d/src/chessboard.cpp b/modules/calib3d/src/chessboard.cpp index 74238ecf84..f72802880a 100644 --- a/modules/calib3d/src/chessboard.cpp +++ b/modules/calib3d/src/chessboard.cpp @@ -2215,11 +2215,13 @@ int Chessboard::Board::detectMarkers(cv::InputArray image) cv::Mat mask = cv::Mat::zeros(DUMMY_FIELD_SIZE,DUMMY_FIELD_SIZE,CV_8UC1); cv::circle(mask,cv::Point(DUMMY_FIELD_SIZE/2,DUMMY_FIELD_SIZE/2),DUMMY_FIELD_SIZE/7,cv::Scalar::all(255),-1); int signal_size = cv::countNonZero(mask); + CV_Assert(signal_size > 0); cv::Mat mask2 = cv::Mat::zeros(DUMMY_FIELD_SIZE,DUMMY_FIELD_SIZE,CV_8UC1); cv::circle(mask2,cv::Point(DUMMY_FIELD_SIZE/2,DUMMY_FIELD_SIZE/2),DUMMY_FIELD_SIZE/2,cv::Scalar::all(255),-1); cv::circle(mask2,cv::Point(DUMMY_FIELD_SIZE/2,DUMMY_FIELD_SIZE/2),DUMMY_FIELD_SIZE/5,cv::Scalar::all(0),-1); int noise_size = cv::countNonZero(mask2); + CV_Assert(noise_size > 0); std::vector dst,src; dst.push_back(cv::Point2f(0.0F,0.0F)); @@ -3369,7 +3371,7 @@ cv::Scalar Chessboard::Board::calcEdgeSharpness(cv::InputArray _img,float rise_d value += patch.at(0,0); ++count2; } - values.push_back(uint8_t(value/count2)); + values.push_back(count2 > 0 ? uint8_t(value/count2) : 0); } float val = calcSharpness(values,rise_distance); diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index c7cdfe3c4f..cfbd155148 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -704,6 +704,7 @@ public: const char* json_signature = "{"; const char* xml_signature = "gets(16); + CV_Assert(buf); char* bufPtr = cv_skip_BOM(buf); size_t bufOffset = bufPtr - buf; diff --git a/modules/features2d/src/kaze/AKAZEFeatures.cpp b/modules/features2d/src/kaze/AKAZEFeatures.cpp index bfba23aa29..0c0332030d 100644 --- a/modules/features2d/src/kaze/AKAZEFeatures.cpp +++ b/modules/features2d/src/kaze/AKAZEFeatures.cpp @@ -1323,6 +1323,7 @@ void quantized_counting_sort(const float a[], const int n, const float quantum, const int nkeys, int idx[/*n*/], int cum[/*nkeys + 1*/]) { + CV_Assert(nkeys > 0); memset(cum, 0, sizeof(cum[0]) * (nkeys + 1)); // Count up the quantized values diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index 3a79c44717..42518da6b0 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -1593,6 +1593,8 @@ bool QRDetectMulti::checkPoints(const vector& quadrangle_points) li2++; } } + if (count_w == 0) + return false; double frac = double(count_b) / double(count_w); double bottom_bound = 0.76;