Skip to content

Fixed issues found by static analysis (mostly DBZ) - #11984

Merged
opencv-pushbot merged 2 commits into
opencv:3.4from
mshabunin:fix-static-1
Jul 17, 2018
Merged

opencv-pushbot merged 2 commits into
opencv:3.4from
mshabunin:fix-static-1

Conversation

@mshabunin

@mshabunin mshabunin commented Jul 16, 2018 •

Copy link
Copy Markdown
Contributor

This pullrequest changes

Added more checks for zero before division

allow_multiple_commits=1

Comment thread modules/calib3d/src/calibration.cpp Outdated
_uu[2] = 1;
cvCrossProduct(&uu, &t, &ww);
nt = cvNorm(&t, 0, CV_L2);
CV_Assert(abs(nt) > 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double nt, nw;

fabs() or std::abs()?

Comment thread modules/imgproc/src/moments.cpp Outdated

Size sz = _src.getSz();
int xtiles = (sz.width + TILE_SIZE-1)/TILE_SIZE;
int ytiles = (sz.height + TILE_SIZE-1)/TILE_SIZE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread modules/imgproc/src/morph.cpp Outdated

int idxArg = kernel.set(0, ocl::KernelArg::PtrReadOnly(source));
idxArg = kernel.set(idxArg, (int)source.step);
CV_Assert(source.elemSize() > 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, may be add this assertion ("dbg" version) into .elemSize() methods directly?

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, UMat::setTo() with empty this crashes with enabled OpenCL.

op == CMP_NE || op == CMP_GE || op == CMP_GT );

if(_src1.empty() && _src2.empty())
if(_src1.empty() || _src2.empty())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no sense to compare some non-empty Mat with empty other Mat.

if(_src1.empty() && _src2.empty())
{
    dst.release();
    return;
}
CV_Assert(!_src1.empty() && !_src2.empty());

I would just raise an error if some Mat is empty (see #8300).

Comment thread modules/core/src/copy.cpp
{
CV_INSTRUMENT_REGION()

if (empty()) return *this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, there should be an exception. See this code.

Comment thread modules/core/src/rand.cpp
InputArray _param1arg, InputArray _param2arg, bool saturateRange )
{
if (_mat.empty())
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.
There is no sense to allow processing of empty data.

@opencv-pushbot
opencv-pushbot merged commit c473718 into opencv:3.4 Jul 17, 2018
@alalek alalek mentioned this pull request Jul 17, 2018
@mshabunin
mshabunin deleted the fix-static-1 branch February 26, 2019 12:08
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants