Fix bug in operator[]: Access is allowed to the terminating null since C++11

This commit is contained in:
Ion Gaztañaga
2026-01-02 18:40:00 +01:00
parent 0a0ea3e694
commit 414e89c781

View File

@@ -1307,7 +1307,7 @@ class basic_string
return *(this->priv_addr() + (this->size() - 1u) );
}
//! <b>Requires</b>: size() > n.
//! <b>Requires</b>: size() >= n.
//!
//! <b>Effects</b>: Returns a reference to the nth element
//! from the beginning of the container.
@@ -1318,11 +1318,11 @@ class basic_string
BOOST_CONTAINER_NODISCARD inline
reference operator[](size_type n) BOOST_NOEXCEPT_OR_NOTHROW
{
BOOST_ASSERT(this->size() > n);
BOOST_ASSERT(this->size() >= n);
return *(this->priv_addr() + difference_type(n));
}
//! <b>Requires</b>: size() > n.
//! <b>Requires</b>: size() >= n.
//!
//! <b>Effects</b>: Returns a const reference to the nth element
//! from the beginning of the container.
@@ -1333,7 +1333,7 @@ class basic_string
BOOST_CONTAINER_NODISCARD inline
const_reference operator[](size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
{
BOOST_ASSERT(this->size() > n);
BOOST_ASSERT(this->size() >= n);
return *(this->priv_addr() + difference_type(n));
}