Closed bharswami closed 11 months ago
I can confirm this. The problem is that operator[]
of the std::vector
failed_rect
is called out of bounds. However, in this case, nothing seems to be done with the value other than taking the address. That's why this does not really cause issues in practice and why this is not found by address sanitizer or valgrind. But still, calling operator[]
out of bounds is undefined behaviour, so the Microsoft STL is correctly detecting this as an error. Compiling with -D_GLIBCXX_DEBUG
makes gcc's stdlibc++ reveal the error too. In fact there are a handful of these in a few places in the code, as this pattern of taking the address of operator[]
's return value is used quite frequently.
A simple fix would be to use the data()
member function instead. That allows doing the pointer arithmetic without indexing into the vector with operator[]
. So &failed_rect[jfail*(m-n)+(nblk-1)*block_size-n]
would become failed_rect.data() + jfail*(m-n)+(nblk-1)*block_size-n
.
Should we do that for the few cases flagged by -D_GLIBCXX_DEBUG
? Or should we replace every case of the &something[]
pattern? The ones that do not cause an error appear to only be used in-bounds, making a change unnecessary. But it's also possible that the tests just do not run into error cases which could potentially still be triggered by different inputs to the library.
Thank you @bharswami for reporting and @mjacobse for confirming.
I'd be tempted for now to just fix the cases flagged up by -D_GLIBCXX_DEBUG
and keep the other (presumably in-bounds) uses of the &something[]
pattern as is since these make the pointer arithmetic involved clearer (at least to me) and avoid a potentially very large change to the codebase that could inadvertently introduce other bugs.
@mjacobse would you be happy to make a PR that fixes the -D_GLIBCXX_DEBUG
cases?
Fixed in #145
I am getting the following index error Unhandled exception at 0x00007FFBB78B829C (ucrtbased.dll) in spraltestfull.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.
if _CONTAINER_DEBUG_LEVEL > 0
endif // _CONTAINER_DEBUG_LEVEL > 0
The higher level functions are (in order, last call first)