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

Patch to avoid out of bounds assert with a debug build on Windows. #1416

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

dlemstra
Copy link
Contributor

This patch fixes an out of range assert with a debug build on Windows:

    _NODISCARD _CONSTEXPR20 const _Ty& operator[](const size_type _Pos) const noexcept /* strengthened */ {
        auto& _My_data = _Mypair._Myval2;
#if _CONTAINER_DEBUG_LEVEL > 0
        _STL_VERIFY(
            _Pos < static_cast<size_type>(_My_data._Mylast - _My_data._Myfirst), "vector subscript out of range");
#endif // _CONTAINER_DEBUG_LEVEL > 0

        return _My_data._Myfirst[_Pos];
    }

This happens when idx + size == indata.size() and can be avoided by getting the address of the last element and then adding 1 to the pointer.

@farindk farindk merged commit fa8082f into strukturag:master Dec 5, 2024
35 checks passed
farindk added a commit that referenced this pull request Dec 5, 2024
@farindk
Copy link
Contributor

farindk commented Dec 5, 2024

Thank you. I have simplified it a bit by avoiding the operator[] altogether for the end pointer.

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.

2 participants