From 414e89c781b7f0efa7ff445a4b7595beeadc05bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 2 Jan 2026 18:40:00 +0100 Subject: [PATCH] Fix bug in operator[]: Access is allowed to the terminating null since C++11 --- include/boost/container/string.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 5b03689..88d8877 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -1307,7 +1307,7 @@ class basic_string return *(this->priv_addr() + (this->size() - 1u) ); } - //! Requires: size() > n. + //! Requires: size() >= n. //! //! Effects: 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)); } - //! Requires: size() > n. + //! Requires: size() >= n. //! //! Effects: 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)); }