Repository navigation
ByteVector, List: Check indices if the standard library does - #1467
Merged
ufleisch merged 1 commit intoOct 31, 2026
Merged
Conversation
If the standard library checks the index in std::vector::operator[] (_GLIBCXX_ASSERTIONS, libc++ hardening modes), ByteVector::operator[] and List::operator[] now check the index against their own size and abort if it is out of range, as std::vector does. The std::vector check alone is not enough: a ByteVector created by mid() shares the buffer of the original byte vector, so an index past the end of the smaller vector still passes it. List::operator[] walks a std::list, which these checks do not cover. Builds without these macros are unchanged; a GCC Release build of libtag produces identical code. The Ubuntu CI job now builds with -D_GLIBCXX_ASSERTIONS so that the tests run with the checks enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
_GLIBCXX_ASSERTIONSor a libc++ hardening mode,std::vector::operator[]is bounds-checked, butByteVector::operator[]andList::operator[]are not. AByteVectorfrommid()shares its parent's buffer, sostd::vectoraccepts an index past the end of the smaller vector.List::operator[]walks astd::list, which these checks don't cover.In those builds, both operators now check against their own size and abort, which makes them harder to misuse. Other builds are unchanged: a GCC Release
libtag.sohas identical code.The Ubuntu CI job now builds with
-D_GLIBCXX_ASSERTIONS. A new test covers indexingmid()results.If it lands, we may submit it to Google's Patch Rewards program, and we'd be glad to share any reward with the maintainers.
— ChipLab