Fix potential overflow in substr; Trac #11536. Also change string_view::copy to use the traits::copy

This commit is contained in:
Marshall Clow
2017-02-13 10:49:17 -08:00
parent 00f02167e3
commit 0876da45db
2 changed files with 3 additions and 9 deletions

View File

@@ -162,9 +162,7 @@ namespace boost {
basic_string_ref substr(size_type pos, size_type n=npos) const {
if ( pos > size())
BOOST_THROW_EXCEPTION( std::out_of_range ( "string_ref::substr" ) );
if ( n == npos || pos + n > size())
n = size () - pos;
return basic_string_ref ( data() + pos, n );
return basic_string_ref(data() + pos, (std::min)(size() - pos, n));
}
int compare(basic_string_ref x) const {