matplotplusplus icon indicating copy to clipboard operation
matplotplusplus copied to clipboard

axes_objects/contourc.cpp:584: out-of-bounds while accessing the _Z_rows[n_col][n_row] in contours::is_lower_level()

Open leha-bot opened this issue 3 years ago • 3 comments

Bug category

  • [ ] bug - compilation error
  • [ ] bug - compilation warning
  • [x] bug - runtime error
  • [ ] bug - runtime warning
  • [x] bug - logic error

Describe the bug At some grids (e.g. transposed) the matplot::contourf() fails with runtime error.

Steps to Reproduce

  1. This error could be triggered by simply swapping X and Y in examples/contour_plots/contourf/contourf_1.cpp
# Your steps go here
mkdir build
cd build
cmake ..  -DCMAKE_BUILD_TYPE=Debug

Output

# The output you got
/usr/include/c++/9/bits/stl_vector.h:1042: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<double>; _Alloc = std::allocator<std::vector<double> >; std::vector<_Tp, _Alloc>::reference = std::vector<double>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed.

Platform

  • [x] cross-platform issue - linux
  • [ ] cross-platform issue - windows
  • [ ] cross-platform issue - macos

Environment Details:

  • OS: CentOS
  • OS Version: 8
  • Compiler: GCC
  • Compiler version: 9.3.1

Additional context

While debugging I found that sometimes the std::find_if() here returns end iterator and at next lines the variables n_row, n_column are could not be adjusted and this is follows to out-of-bounds error in header. The dirty hack is the simply decrement n_row, n_col after checking all directions and before determining the opposite points here, but I doubt in robustness of this fix. @alandefreitas what do you think?

leha-bot avatar Oct 06 '20 15:10 leha-bot

This is fixed, right?

alandefreitas avatar Oct 19 '20 19:10 alandefreitas

Unfortunately no, we should decide how to deal with https://github.com/alandefreitas/matplotplusplus/blob/7b3c04281bc53fad77435d4f79b75fb228ebe87e/source/matplot/axes_objects/contours.cpp#L540-L545 if std::find_if returns end iterator, as my supposed fix in issue description for this place is not good and robust;

leha-bot avatar Oct 23 '20 10:10 leha-bot

OK. I'll have a look at that.

alandefreitas avatar Oct 23 '20 22:10 alandefreitas