More issues found by static analysis

pull/12048/head
Maksim Shabunin 6 years ago
parent 8de08e0463
commit cbb1e867e5
  1. 4
      apps/createsamples/utility.cpp
  2. 22
      modules/calib3d/src/circlesgrid.cpp
  3. 2
      modules/calib3d/src/dls.cpp
  4. 8
      modules/calib3d/test/test_chesscorners.cpp
  5. 9
      modules/core/src/persistence_json.cpp
  6. 4
      modules/core/test/test_mat.cpp
  7. 8
      modules/core/test/test_rand.cpp
  8. 3
      modules/dnn/src/layers/convolution_layer.cpp
  9. 2
      modules/dnn/src/layers/eltwise_layer.cpp
  10. 1
      modules/dnn/src/layers/normalize_bbox_layer.cpp
  11. 6
      modules/dnn/src/layers/recurrent_layers.cpp
  12. 4
      modules/features2d/src/brisk.cpp
  13. 2
      modules/features2d/src/kaze/KAZEFeatures.cpp
  14. 1
      modules/imgcodecs/src/exif.cpp
  15. 7
      modules/imgcodecs/src/grfmt_bmp.cpp
  16. 2
      modules/imgcodecs/src/grfmt_pam.cpp
  17. 9
      modules/imgcodecs/src/grfmt_tiff.cpp
  18. 6
      modules/imgproc/src/contours.cpp
  19. 4
      modules/imgproc/src/drawing.cpp
  20. 7
      modules/imgproc/src/filter.avx2.cpp
  21. 7
      modules/imgproc/src/floodfill.cpp
  22. 4
      modules/imgproc/src/histogram.cpp
  23. 1
      modules/imgproc/src/hough.cpp
  24. 1
      modules/imgproc/src/min_enclosing_triangle.cpp
  25. 2
      modules/ml/src/ann_mlp.cpp
  26. 3
      modules/videoio/src/cap_ffmpeg_impl.hpp
  27. 3
      modules/videoio/src/container_avi.cpp

@ -1044,12 +1044,10 @@ void cvCreateTrainingSamples( const char* filename,
output = fopen( filename, "wb" );
if( output != NULL )
{
int hasbg;
int i;
int inverse;
hasbg = 0;
hasbg = (bgfilename != NULL && icvInitBackgroundReaders( bgfilename,
const int hasbg = (bgfilename != NULL && icvInitBackgroundReaders( bgfilename,
Size( winwidth,winheight ) ) );
Mat sample( winheight, winwidth, CV_8UC1 );

@ -224,7 +224,7 @@ void CirclesGridClusterFinder::findOutsideCorners(const std::vector<cv::Point2f>
CV_Assert(!corners.empty());
outsideCorners.clear();
//find two pairs of the most nearest corners
int i, j, n = (int)corners.size();
const size_t n = corners.size();
#ifdef DEBUG_CIRCLES
Mat cornersImage(1024, 1248, CV_8UC1, Scalar(0));
@ -232,22 +232,22 @@ void CirclesGridClusterFinder::findOutsideCorners(const std::vector<cv::Point2f>
imshow("corners", cornersImage);
#endif
std::vector<Point2f> tangentVectors(corners.size());
for(size_t k=0; k<corners.size(); k++)
std::vector<Point2f> tangentVectors(n);
for(size_t k=0; k < n; k++)
{
Point2f diff = corners[(k + 1) % corners.size()] - corners[k];
Point2f diff = corners[(k + 1) % n] - corners[k];
tangentVectors[k] = diff * (1.0f / norm(diff));
}
//compute angles between all sides
Mat cosAngles(n, n, CV_32FC1, 0.0f);
for(i = 0; i < n; i++)
Mat cosAngles((int)n, (int)n, CV_32FC1, 0.0f);
for(size_t i = 0; i < n; i++)
{
for(j = i + 1; j < n; j++)
for(size_t j = i + 1; j < n; j++)
{
float val = fabs(tangentVectors[i].dot(tangentVectors[j]));
cosAngles.at<float>(i, j) = val;
cosAngles.at<float>(j, i) = val;
cosAngles.at<float>((int)i, (int)j) = val;
cosAngles.at<float>((int)j, (int)i) = val;
}
}
@ -276,10 +276,10 @@ void CirclesGridClusterFinder::findOutsideCorners(const std::vector<cv::Point2f>
const int bigDiff = 4;
if(maxIdx - minIdx == bigDiff)
{
minIdx += n;
minIdx += (int)n;
std::swap(maxIdx, minIdx);
}
if(maxIdx - minIdx != n - bigDiff)
if(maxIdx - minIdx != (int)n - bigDiff)
{
return;
}

@ -206,7 +206,7 @@ void dls::run_kernel(const cv::Mat& pp)
void dls::build_coeff_matrix(const cv::Mat& pp, cv::Mat& Mtilde, cv::Mat& D)
{
CV_Assert(!pp.empty());
CV_Assert(!pp.empty() && N > 0);
cv::Mat eye = cv::Mat::eye(3, 3, CV_64F);
// build coeff matrix

@ -334,19 +334,19 @@ bool validateData(const ChessBoardGenerator& cbg, const Size& imgSz,
tmp = cv::norm(cur - mat(i + 1, j + 1)); // TODO cvtest
if (tmp < minNeibDist)
tmp = minNeibDist;
minNeibDist = tmp;
tmp = cv::norm(cur - mat(i - 1, j + 1)); // TODO cvtest
if (tmp < minNeibDist)
tmp = minNeibDist;
minNeibDist = tmp;
tmp = cv::norm(cur - mat(i + 1, j - 1)); // TODO cvtest
if (tmp < minNeibDist)
tmp = minNeibDist;
minNeibDist = tmp;
tmp = cv::norm(cur - mat(i - 1, j - 1)); // TODO cvtest
if (tmp < minNeibDist)
tmp = minNeibDist;
minNeibDist = tmp;
}
const double threshold = 0.25;

@ -123,7 +123,6 @@ static char* icvJSONParseKey( CvFileStorage* fs, char* ptr, CvFileNode* map, CvF
CV_PARSE_ERROR( "Key must start with \'\"\'" );
char * beg = ptr + 1;
char * end = beg;
do {
++ptr;
@ -133,7 +132,7 @@ static char* icvJSONParseKey( CvFileStorage* fs, char* ptr, CvFileNode* map, CvF
if( *ptr != '"' )
CV_PARSE_ERROR( "Key must end with \'\"\'" );
end = ptr;
const char * end = ptr;
ptr++;
ptr = icvJSONSkipSpaces( fs, ptr );
if ( ptr == 0 || fs->dummy_eof )
@ -576,12 +575,12 @@ void icvJSONParse( CvFileStorage* fs )
if ( *ptr == '{' )
{
CvFileNode* root_node = (CvFileNode*)cvSeqPush( fs->roots, 0 );
ptr = icvJSONParseMap( fs, ptr, root_node );
icvJSONParseMap( fs, ptr, root_node );
}
else if ( *ptr == '[' )
{
CvFileNode* root_node = (CvFileNode*)cvSeqPush( fs->roots, 0 );
ptr = icvJSONParseSeq( fs, ptr, root_node );
icvJSONParseSeq( fs, ptr, root_node );
}
else
{
@ -668,7 +667,7 @@ void icvJSONWrite( CvFileStorage* fs, const char* key, const char* data )
*ptr++ = '\n';
*ptr++ = '\0';
::icvPuts( fs, fs->buffer_start );
ptr = fs->buffer = fs->buffer_start;
fs->buffer = fs->buffer_start;
}
ptr = icvFSFlush(fs);
}

@ -1014,8 +1014,8 @@ protected:
Size mSize(rng.uniform(minMSize, maxMSize), rng.uniform(minMSize, maxMSize));
size_t mvSize = rng.uniform(1, maxMvSize);
int res = cvtest::TS::OK, curRes = res;
curRes = run_case(CV_8U, mvSize, mSize, rng);
int res = cvtest::TS::OK;
int curRes = run_case(CV_8U, mvSize, mSize, rng);
res = curRes != cvtest::TS::OK ? curRes : res;
curRes = run_case(CV_8S, mvSize, mSize, rng);

@ -375,9 +375,11 @@ TEST(Core_Rand, Regression_Stack_Corruption)
int bufsz = 128; //enough for 14 doubles
AutoBuffer<uchar> buffer(bufsz);
size_t offset = 0;
cv::Mat_<cv::Point2d> x(2, 3, (cv::Point2d*)(buffer.data()+offset)); offset += x.total()*x.elemSize();
double& param1 = *(double*)(buffer.data()+offset); offset += sizeof(double);
double& param2 = *(double*)(buffer.data()+offset); offset += sizeof(double);
cv::Mat_<cv::Point2d> x(2, 3, (cv::Point2d*)(buffer.data()+offset));
offset += x.total()*x.elemSize();
double& param1 = *(double*)(buffer.data()+offset);
offset += sizeof(double);
double& param2 = *(double*)(buffer.data()+offset);
param1 = -9; param2 = 2;
cv::theRNG().fill(x, cv::RNG::NORMAL, param1, param2);

@ -560,7 +560,7 @@ public:
int ngroups = ngroups_, batchSize = input_->size[0]*ngroups;
int outW = output_->size[3], outH = output_->size[2], outCn = output_->size[1]/ngroups;
int width = input_->size[3], height = input_->size[2], inpCn = input_->size[1]/ngroups;
int nstripes = nstripes_;
const int nstripes = nstripes_;
int kernel_w = kernel_.width, kernel_h = kernel_.height;
int pad_w = pad_.width, pad_h = pad_.height;
int stride_w = stride_.width, stride_h = stride_.height;
@ -587,7 +587,6 @@ public:
int samplesPerStripe = std::max((batchSize + nstripes - 1)/nstripes, 1);
r.start *= samplesPerStripe;
r.end *= samplesPerStripe;
nstripes *= samplesPerStripe;
stripeSize = outPlaneSize;
}

@ -187,7 +187,7 @@ public:
int c, j, k, n = nsrcs;
const float* coeffsptr = coeffs && !coeffs->empty() ? &coeffs->at(0) : 0;
float* dstptr0 = dst->ptr<float>();
int blockSize0 = 1 << 12, blockSize = blockSize0;
int blockSize0 = 1 << 12, blockSize;
for( size_t ofs = stripeStart; ofs < stripeEnd; ofs += blockSize )
{

@ -190,6 +190,7 @@ public:
size_t num = total(shape(inp0.size), 0, startAxis);
size_t numPlanes = total(shape(inp0.size), startAxis, endAxis + 1);
CV_Assert(num * numPlanes != 0);
size_t planeSize = inp0.total() / (num * numPlanes);
for (size_t n = 0; n < num; ++n)
{

@ -189,18 +189,16 @@ public:
else
outTailShape_.assign(1, _numOut);
int _numTimeStamps, _numSamples;
int _numSamples;
if (useTimestampDim)
{
CV_Assert(inp0.size() >= 2 && total(inp0, 2) == _numInp);
_numTimeStamps = inp0[0];
_numSamples = inp0[1];
outResShape.push_back(_numTimeStamps);
outResShape.push_back(inp0[0]);
}
else
{
CV_Assert(inp0.size() >= 2 && total(inp0, 1) == _numInp);
_numTimeStamps = 1;
_numSamples = inp0[0];
}

@ -1236,7 +1236,6 @@ BriskScaleSpace::isMax2D(const int layer, const int x_layer, const int y_layer)
{
// in this case, we have to analyze the situation more carefully:
// the values are gaussian blurred and then we really decide
data = scores.ptr() + y_layer * scorescols + x_layer;
int smoothedcenter = 4 * center + 2 * (s_10 + s10 + s0_1 + s01) + s_1_1 + s1_1 + s_11 + s11;
for (unsigned int i = 0; i < deltasize; i += 2)
{
@ -1312,8 +1311,7 @@ BriskScaleSpace::refine3D(const int layer, const int x_layer, const int y_layer,
int s_2_2 = l.getAgastScore_5_8(x_layer + 1, y_layer + 1, 1);
max_below = std::max(s_2_2, max_below);
max_below_float = subpixel2D(s_0_0, s_0_1, s_0_2, s_1_0, s_1_1, s_1_2, s_2_0, s_2_1, s_2_2, delta_x_below,
delta_y_below);
subpixel2D(s_0_0, s_0_1, s_0_2, s_1_0, s_1_1, s_1_2, s_2_0, s_2_1, s_2_2, delta_x_below, delta_y_below);
max_below_float = (float)max_below;
}
else

@ -373,8 +373,6 @@ void KAZEFeatures::Determinant_Hessian(std::vector<KeyPoint>& kpts)
is_out = true;
}
is_out = false;
if (is_out == false) {
if (is_repeated == false) {
kpts.push_back(kpts_par_[i][j]);

@ -175,7 +175,6 @@ std::map<int, ExifEntry_t > ExifReader::getExif()
CV_THROW (ExifParsingError());
}
m_stream.read( reinterpret_cast<char*>(&m_data[0]), exifSize - offsetToTiffHeader );
count = m_stream.gcount();
exifFound = true;
break;

@ -265,7 +265,7 @@ bool BmpDecoder::readData( Mat& img )
for(;;)
{
int code = m_strm.getWord();
int len = code & 255;
const int len = code & 255;
code >>= 8;
if( len != 0 ) // encoded mode
{
@ -304,16 +304,13 @@ bool BmpDecoder::readData( Mat& img )
else
{
int x_shift3 = (int)(line_end - data);
int y_shift = m_height - y;
if( code == 2 )
{
x_shift3 = m_strm.getByte()*nch;
y_shift = m_strm.getByte();
m_strm.getByte();
}
len = x_shift3 + ((y_shift * width3) & ((code == 0) - 1));
if( color )
data = FillUniColor( data, line_end, step, width3,
y, m_height, x_shift3,

@ -689,7 +689,7 @@ bool PAMEncoder::write( const Mat& img, const std::vector<int>& params )
tmp += sprintf( buffer + tmp, "MAXVAL %d\n", (1 << img.elemSize1()*8) - 1);
if (fmt)
tmp += sprintf( buffer + tmp, "TUPLTYPE %s\n", fmt->name );
tmp += sprintf( buffer + tmp, "ENDHDR\n" );
sprintf( buffer + tmp, "ENDHDR\n" );
strm.putBytes( buffer, (int)strlen(buffer) );
/* write data */

@ -255,22 +255,21 @@ bool TiffDecoder::readHeader()
{
case 8:
m_type = CV_MAKETYPE(CV_8U, photometric > 1 ? wanted_channels : 1);
result = true;
break;
case 16:
m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? wanted_channels : 1);
result = true;
break;
case 32:
m_type = CV_MAKETYPE(CV_32F, photometric > 1 ? 3 : 1);
result = true;
break;
case 64:
m_type = CV_MAKETYPE(CV_64F, photometric > 1 ? 3 : 1);
result = true;
break;
default:
result = false;
}
result = true;
}
}

@ -855,7 +855,6 @@ icvTraceContour_32s( int *ptr, int step, int *stop_ptr, int is_hole )
for( ;; )
{
CV_Assert(i3 != NULL);
s_end = s;
s = std::min(s, MAX_SIZE - 1);
while( s < MAX_SIZE - 1 )
@ -1479,7 +1478,7 @@ icvFindContoursInInterval( const CvArr* src,
cv::Ptr<CvMemStorage> storage01;
CvSeq* first = 0;
int i, j, k, n;
int j, k, n;
uchar* src_data = 0;
int img_step = 0;
@ -1547,7 +1546,6 @@ icvFindContoursInInterval( const CvArr* src,
// First line. None of runs is binded
tmp.pt.y = 0;
i = 0;
CV_WRITE_SEQ_ELEM( tmp, writer );
upper_line = (CvLinkedRunPoint*)CV_GET_WRITTEN_ELEM( writer );
@ -1580,7 +1578,7 @@ icvFindContoursInInterval( const CvArr* src,
last_elem = tmp_prev;
tmp_prev->next = 0;
for( i = 1; i < img_size.height; i++ )
for( int i = 1; i < img_size.height; i++ )
{
//------// Find runs in next line
src_data += img_step;

@ -338,7 +338,6 @@ LineAA( Mat& img, Point2l pt1, Point2l pt2, const void* color )
if( ax > ay )
{
dx = ax;
dy = (dy ^ j) - j;
pt1.x ^= pt2.x & j;
pt2.x ^= pt1.x & j;
@ -362,7 +361,6 @@ LineAA( Mat& img, Point2l pt1, Point2l pt2, const void* color )
}
else
{
dy = ay;
dx = (dx ^ i) - i;
pt1.x ^= pt2.x & i;
pt2.x ^= pt1.x & i;
@ -677,7 +675,6 @@ Line2( Mat& img, Point2l pt1, Point2l pt2, const void* color)
if( ax > ay )
{
dx = ax;
dy = (dy ^ j) - j;
pt1.x ^= pt2.x & j;
pt2.x ^= pt1.x & j;
@ -692,7 +689,6 @@ Line2( Mat& img, Point2l pt1, Point2l pt2, const void* color)
}
else
{
dy = ay;
dx = (dx ^ i) - i;
pt1.x ^= pt2.x & i;
pt2.x ^= pt1.x & i;

@ -128,8 +128,6 @@ int SymmColumnVec_32f_Symm_AVX(const float** src, const float* ky, float* dst, f
for( k = 1; k <= ksize2; k++ )
{
f = _mm_set1_ps(ky[k]);
S = src[k] + i;
S2 = src[-k] + i;
x0 = _mm_add_ps(_mm_load_ps(src[k]+i), _mm_load_ps(src[-k] + i));
s0 = _mm_add_ps(s0, _mm_mul_ps(x0, f));
}
@ -144,7 +142,7 @@ int SymmColumnVec_32f_Symm_AVX(const float** src, const float* ky, float* dst, f
int SymmColumnVec_32f_Unsymm_AVX(const float** src, const float* ky, float* dst, float delta, int width, int ksize2)
{
int i = 0, k;
const float *S, *S2;
const float *S2;
const __m128 d4 = _mm_set1_ps(delta);
const __m256 d8 = _mm256_set1_ps(delta);
@ -152,11 +150,10 @@ int SymmColumnVec_32f_Unsymm_AVX(const float** src, const float* ky, float* dst,
{
__m256 f, s0 = d8, s1 = d8;
__m256 x0;
S = src[0] + i;
for (k = 1; k <= ksize2; k++)
{
S = src[k] + i;
const float *S = src[k] + i;
S2 = src[-k] + i;
f = _mm256_set1_ps(ky[k]);
x0 = _mm256_sub_ps(_mm256_loadu_ps(S), _mm256_loadu_ps(S2));

@ -467,7 +467,7 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask,
if( rect )
*rect = Rect();
int i, connectivity = flags & 255;
int i;
union {
uchar b[4];
int i[4];
@ -491,9 +491,8 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask,
CV_Error( CV_StsBadArg, "Number of channels in input image must be 1 or 3" );
}
if( connectivity == 0 )
connectivity = 4;
else if( connectivity != 4 && connectivity != 8 )
const int connectivity = flags & 255;
if( connectivity != 0 && connectivity != 4 && connectivity != 8 )
CV_Error( CV_StsBadFlag, "Connectivity must be 4, 0(=4) or 8" );
bool is_simple = mask.empty() && (flags & FLOODFILL_MASK_ONLY) == 0;

@ -1930,7 +1930,7 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
Mat planes[2];
NAryMatIterator it(arrays, planes);
double result = 0;
int j, len = (int)it.size;
int j;
CV_Assert( H1.type() == H2.type() && H1.depth() == CV_32F );
@ -1946,7 +1946,7 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
{
const float* h1 = it.planes[0].ptr<float>();
const float* h2 = it.planes[1].ptr<float>();
len = it.planes[0].rows*it.planes[0].cols*H1.channels();
const int len = it.planes[0].rows*it.planes[0].cols*H1.channels();
j = 0;
if( (method == CV_COMP_CHISQR) || (method == CV_COMP_CHISQR_ALT))

@ -413,7 +413,6 @@ HoughLinesSDiv( InputArray image, OutputArray lines, int type,
// Find peaks in maccum...
for( index = 0; index < sfn; index++ )
{
i = 0;
int pos = (int)(lst.size() - 1);
if( pos < 0 || lst[pos].value < mcaccum[index] )
{

@ -401,7 +401,6 @@ static void findMinimumAreaEnclosingTriangle(const std::vector<cv::Point2f> &pol
a = 1;
b = 2;
c = 0;
// Main algorithm steps

@ -1259,7 +1259,7 @@ public:
prev_dEdw_sign[i] = Mat::zeros(weights[i].size(), CV_8S);
dEdw[i] = Mat::zeros(weights[i].size(), CV_64F);
}
CV_Assert(total > 0);
int dcount0 = max_buf_size/(2*total);
dcount0 = std::max( dcount0, 1 );
dcount0 = std::min( dcount0, count );

@ -2351,9 +2351,6 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CV_CODEC
c->codec_type = AVMEDIA_TYPE_VIDEO;
// put sample parameters
unsigned long long lbit_rate = static_cast<unsigned long long>(bitrate);
lbit_rate += (bitrate / 4);
lbit_rate = std::min(lbit_rate, static_cast<unsigned long long>(std::numeric_limits<int>::max()));
c->bit_rate = bitrate;
// took advice from

@ -325,9 +325,6 @@ bool AVIReadContainer::parseStrl(char stream_id, Codecs codec_)
if(m_file_stream && strh.m_four_cc == STRH_CC)
{
uint64_t next_strl_list = m_file_stream->tellg();
next_strl_list += strh.m_size;
AviStreamHeader strm_hdr;
*m_file_stream >> strm_hdr;

Loading…
Cancel
Save