From f373c58f9abc80b21e7f4f65dd041c453d56811d Mon Sep 17 00:00:00 2001 From: John Carter Date: Fri, 1 Nov 2002 15:25:27 +0000 Subject: [PATCH] re PR libstdc++/7961 (compare( char *) implemented incorrectly.) 2002-11-01 John Carter PR libstdc++/7961 * include/bits/basic_string.tcc (compare(const _CharT* __s)): Don't access __s past its length. From-SVN: r58718 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/basic_string.tcc | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ec6a1f5fa4a7..0bf34cbaef08 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2002-11-01 John Carter + + PR libstdc++/7961 + * include/bits/basic_string.tcc + (compare(const _CharT* __s)): Don't access __s past its length. + 2002-11-01 Hans-Peter Nilsson PR other/3337 diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 322528c90aa2..198f190eae89 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -497,7 +497,6 @@ namespace std this->erase(__n); // else nothing (in particular, avoid calling _M_mutate() unnecessarily.) } - // This is the general replace helper, which currently gets instantiated both // for input iterators and reverse iterators. It buffers internally and then @@ -885,9 +884,11 @@ namespace std compare(const _CharT* __s) const { size_type __size = this->size(); - int __r = traits_type::compare(_M_data(), __s, __size); + size_type __osize = traits_type::length(__s); + size_type __len = min(__size, __osize); + int __r = traits_type::compare(_M_data(), __s, __len); if (!__r) - __r = __size - traits_type::length(__s); + __r = __size - __osize; return __r; } -- 2.47.2