From 7ac95c156c9256e9e15cc430c82f39dd588c2451 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Tue, 3 May 2022 00:38:15 +0300 Subject: [PATCH] Fixed string_view/ref::max_size() returning incorrect value. Fixes https://github.com/boostorg/utility/issues/91. --- include/boost/utility/string_ref.hpp | 2 +- include/boost/utility/string_view.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/string_ref.hpp b/include/boost/utility/string_ref.hpp index 6e8ecc5..ffadb2e 100644 --- a/include/boost/utility/string_ref.hpp +++ b/include/boost/utility/string_ref.hpp @@ -128,7 +128,7 @@ namespace boost { // capacity BOOST_CONSTEXPR size_type size() const { return len_; } BOOST_CONSTEXPR size_type length() const { return len_; } - BOOST_CONSTEXPR size_type max_size() const { return len_; } + BOOST_CONSTEXPR size_type max_size() const { return ~static_cast(0) / (sizeof(value_type) * 2u); } BOOST_CONSTEXPR bool empty() const { return len_ == 0; } // element access diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 30837e4..fe1cfa0 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -122,7 +122,7 @@ namespace boost { // capacity BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT { return len_; } BOOST_CONSTEXPR size_type length() const BOOST_NOEXCEPT { return len_; } - BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { return len_; } + BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { return ~static_cast(0) / (sizeof(value_type) * 2u); } BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT { return len_ == 0; } // element access