mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #12391 from DEEPIR:master
fix some errors found by static analyzer. (#12391) * fix possible divided by zero and by negative values * only 4 elements are used in these arrays * fix uninitialized member * use boolean type for semantic boolean variables * avoid invalid array index * to avoid exception and because base64_beg is only used in this block * use std::atomic<bool> to avoid thread control race condition
This commit is contained in:
parent
f826709452
commit
10fb88d027
@ -939,7 +939,7 @@ bool _InputArray::isContinuous(int i) const
|
|||||||
if( k == STD_VECTOR_MAT )
|
if( k == STD_VECTOR_MAT )
|
||||||
{
|
{
|
||||||
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
|
const std::vector<Mat>& vv = *(const std::vector<Mat>*)obj;
|
||||||
CV_Assert((size_t)i < vv.size());
|
CV_Assert(i >= 0 && (size_t)i < vv.size());
|
||||||
return vv[i].isContinuous();
|
return vv[i].isContinuous();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,7 +953,7 @@ bool _InputArray::isContinuous(int i) const
|
|||||||
if( k == STD_VECTOR_UMAT )
|
if( k == STD_VECTOR_UMAT )
|
||||||
{
|
{
|
||||||
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
|
const std::vector<UMat>& vv = *(const std::vector<UMat>*)obj;
|
||||||
CV_Assert((size_t)i < vv.size());
|
CV_Assert(i >= 0 && (size_t)i < vv.size());
|
||||||
return vv[i].isContinuous();
|
return vv[i].isContinuous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ public:
|
|||||||
std::atomic<int> completed_thread_count; // number of threads completed any activities on this job
|
std::atomic<int> completed_thread_count; // number of threads completed any activities on this job
|
||||||
int64 dummy2_[8]; // avoid cache-line reusing for the same atomics
|
int64 dummy2_[8]; // avoid cache-line reusing for the same atomics
|
||||||
|
|
||||||
volatile bool is_completed; // std::atomic_flag ?
|
std::atomic<bool> is_completed;
|
||||||
|
|
||||||
// TODO exception handling
|
// TODO exception handling
|
||||||
};
|
};
|
||||||
|
@ -238,11 +238,11 @@ static char* icvJSONParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node )
|
|||||||
CV_PARSE_ERROR("Invalid `dt` in Base64 header");
|
CV_PARSE_ERROR("Invalid `dt` in Base64 header");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set base64_beg to beginning of base64 data */
|
|
||||||
base64_beg = &base64_buffer.at( base64::ENCODED_HEADER_SIZE );
|
|
||||||
|
|
||||||
if ( base64_buffer.size() > base64::ENCODED_HEADER_SIZE )
|
if ( base64_buffer.size() > base64::ENCODED_HEADER_SIZE )
|
||||||
{
|
{
|
||||||
|
/* set base64_beg to beginning of base64 data */
|
||||||
|
base64_beg = &base64_buffer.at( base64::ENCODED_HEADER_SIZE );
|
||||||
if ( !base64::base64_valid( base64_beg, 0U, base64_end - base64_beg ) )
|
if ( !base64::base64_valid( base64_beg, 0U, base64_end - base64_beg ) )
|
||||||
CV_PARSE_ERROR( "Invalid Base64 data." );
|
CV_PARSE_ERROR( "Invalid Base64 data." );
|
||||||
|
|
||||||
|
@ -451,7 +451,6 @@ namespace
|
|||||||
Size block_size;
|
Size block_size;
|
||||||
Size user_block_size;
|
Size user_block_size;
|
||||||
Size dft_size;
|
Size dft_size;
|
||||||
int spect_len;
|
|
||||||
|
|
||||||
GpuMat image_spect, templ_spect, result_spect;
|
GpuMat image_spect, templ_spect, result_spect;
|
||||||
GpuMat image_block, templ_block, result_data;
|
GpuMat image_block, templ_block, result_data;
|
||||||
@ -484,7 +483,7 @@ namespace
|
|||||||
createContinuous(dft_size, CV_32F, templ_block);
|
createContinuous(dft_size, CV_32F, templ_block);
|
||||||
createContinuous(dft_size, CV_32F, result_data);
|
createContinuous(dft_size, CV_32F, result_data);
|
||||||
|
|
||||||
spect_len = dft_size.height * (dft_size.width / 2 + 1);
|
int spect_len = dft_size.height * (dft_size.width / 2 + 1);
|
||||||
createContinuous(1, spect_len, CV_32FC2, image_spect);
|
createContinuous(1, spect_len, CV_32FC2, image_spect);
|
||||||
createContinuous(1, spect_len, CV_32FC2, templ_spect);
|
createContinuous(1, spect_len, CV_32FC2, templ_spect);
|
||||||
createContinuous(1, spect_len, CV_32FC2, result_spect);
|
createContinuous(1, spect_len, CV_32FC2, result_spect);
|
||||||
|
@ -179,7 +179,7 @@ bool Jpeg2KDecoder::readData( Mat& img )
|
|||||||
{
|
{
|
||||||
Ptr<Jpeg2KDecoder> close_this(this, Jpeg2KDecoder_close);
|
Ptr<Jpeg2KDecoder> close_this(this, Jpeg2KDecoder_close);
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int color = img.channels() > 1;
|
bool color = img.channels() > 1;
|
||||||
uchar* data = img.ptr();
|
uchar* data = img.ptr();
|
||||||
size_t step = img.step;
|
size_t step = img.step;
|
||||||
jas_stream_t* stream = (jas_stream_t*)m_stream;
|
jas_stream_t* stream = (jas_stream_t*)m_stream;
|
||||||
|
@ -226,7 +226,7 @@ bool PngDecoder::readData( Mat& img )
|
|||||||
volatile bool result = false;
|
volatile bool result = false;
|
||||||
AutoBuffer<uchar*> _buffer(m_height);
|
AutoBuffer<uchar*> _buffer(m_height);
|
||||||
uchar** buffer = _buffer.data();
|
uchar** buffer = _buffer.data();
|
||||||
int color = img.channels() > 1;
|
bool color = img.channels() > 1;
|
||||||
|
|
||||||
png_structp png_ptr = (png_structp)m_png_ptr;
|
png_structp png_ptr = (png_structp)m_png_ptr;
|
||||||
png_infop info_ptr = (png_infop)m_info_ptr;
|
png_infop info_ptr = (png_infop)m_info_ptr;
|
||||||
|
@ -208,7 +208,7 @@ bool PxMDecoder::readHeader()
|
|||||||
|
|
||||||
bool PxMDecoder::readData( Mat& img )
|
bool PxMDecoder::readData( Mat& img )
|
||||||
{
|
{
|
||||||
int color = img.channels() > 1;
|
bool color = img.channels() > 1;
|
||||||
uchar* data = img.ptr();
|
uchar* data = img.ptr();
|
||||||
PaletteEntry palette[256];
|
PaletteEntry palette[256];
|
||||||
bool result = false;
|
bool result = false;
|
||||||
@ -225,7 +225,7 @@ bool PxMDecoder::readData( Mat& img )
|
|||||||
// create LUT for converting colors
|
// create LUT for converting colors
|
||||||
if( bit_depth == 8 )
|
if( bit_depth == 8 )
|
||||||
{
|
{
|
||||||
CV_Assert(m_maxval < 256);
|
CV_Assert(m_maxval < 256 && m_maxval > 0);
|
||||||
|
|
||||||
for (int i = 0; i <= m_maxval; i++)
|
for (int i = 0; i <= m_maxval; i++)
|
||||||
gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0));
|
gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0));
|
||||||
|
@ -160,7 +160,7 @@ bool SunRasterDecoder::readHeader()
|
|||||||
|
|
||||||
bool SunRasterDecoder::readData( Mat& img )
|
bool SunRasterDecoder::readData( Mat& img )
|
||||||
{
|
{
|
||||||
int color = img.channels() > 1;
|
bool color = img.channels() > 1;
|
||||||
uchar* data = img.ptr();
|
uchar* data = img.ptr();
|
||||||
size_t step = img.step;
|
size_t step = img.step;
|
||||||
uchar gray_palette[256] = {0};
|
uchar gray_palette[256] = {0};
|
||||||
|
@ -321,7 +321,7 @@ static void fitLine2D( const Point2f * points, int count, int dist,
|
|||||||
void (*calc_weights) (float *, int, float *) = 0;
|
void (*calc_weights) (float *, int, float *) = 0;
|
||||||
void (*calc_weights_param) (float *, int, float *, float) = 0;
|
void (*calc_weights_param) (float *, int, float *, float) = 0;
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
float _line[6], _lineprev[6];
|
float _line[4], _lineprev[4];
|
||||||
float rdelta = reps != 0 ? reps : 1.0f;
|
float rdelta = reps != 0 ? reps : 1.0f;
|
||||||
float adelta = aeps != 0 ? aeps : 0.01f;
|
float adelta = aeps != 0 ? aeps : 0.01f;
|
||||||
double min_err = DBL_MAX, err = 0;
|
double min_err = DBL_MAX, err = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user