No segmentation fault while it should

asked 2019-06-27 03:45:15 -0600

BuenaVentura gravatar image

Sometimes I do not get a segmentation fault (while I should) when I access the image with:<uchar>()

For example, if I declare an image of size 800 x 800 and access a pixel outside this range I may not get a segmentation fault. E.g.

Mat image_test(800, 800, CV_8UC1, Scalar(0));
std::cout << "value: " << (int)<uchar>(850, 2) << std::endl;

In the code above it just prints a value 146 which is of course impossible since all pixels are initialized with zero. My question is what does really happen behind the scene?

edit retag flag offensive close merge delete


debug mode should trigger an exception there.

(also, 850x2 is still insde the linear image memory, try 900x900 or such.)

berak gravatar imageberak ( 2019-06-27 03:53:27 -0600 )edit

Tried with<uchar>(900, 900) and still not segmentation fault. Can I enable debug mode with gcc? Because I do not use cmake for this project.. Also how do you know the space of linear memory?

BuenaVentura gravatar imageBuenaVentura ( 2019-06-27 04:01:03 -0600 )edit

gcc -g my.cpp ...

but then you have to link to debug opencv libs, too, meaning, you probably need a 2nd cmake/make/make install pass

berak gravatar imageberak ( 2019-06-27 08:45:09 -0600 )edit