Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out of bounds std::vector subscript operator usage #145

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

mjacobse
Copy link
Collaborator

Fixes #140. This was the minimum amount of replacements with .data() that causes no errors with -D_GLIBCXX_DEBUG for me across all tests.

In several places, the std::vector subscript operator[] is used
together with the addressof operator to obtain a pointer into the
vector. In some cases, this is intended to yield a pointer past the
end of the vector. In such cases, the pointer is not actually used
to read from or write to. Thus it causes no actual problems in
practice and even address sanitizer and valgrind are happy with it.
However, operator[] is still called with an out of bounds index,
which is undefined behaviour. This is correctly detected by
Microsofts standard library debug checks and also by GNU's library
once compiling with -D_GLIBCXX_DEBUG.

As a fix, we use .data() and pointer arithmetic to get to the
intended pointer without any out of bound access. Fixes ralna#140
@jfowkes
Copy link
Contributor

jfowkes commented Sep 22, 2023

Many thanks @mjacobse this looks great to me!

@jfowkes jfowkes self-requested a review September 22, 2023 13:46
@jfowkes jfowkes merged commit 1db261a into ralna:master Sep 22, 2023
4 checks passed
@mjacobse mjacobse deleted the fix_vector_oob_access branch September 22, 2023 13:47
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.

Error while running tests (ldlt_app.cpp)
2 participants