ByteVector, List: Check indices if the standard library does (#1467)

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 commit is contained in:
Nathan Chandrasekar
2026-10-31 12:07:55 +01:00
committed by GitHub
parent cfb9a7d8a9
commit 50ca520b27
4 changed files with 60 additions and 0 deletions
+2
View File
@@ -11,6 +11,8 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest, windows-2025, ubuntu-26.04]
include:
- os: ubuntu-latest
cmake_extra_args: '-DCMAKE_CXX_FLAGS="-D_GLIBCXX_ASSERTIONS"'
- os: windows-latest
cmake_extra_args: '-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake"'
- os: windows-2025