]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/7961 (compare( char *) implemented incorrectly.)
authorJohn Carter <john.carter@tait.co.nz>
Fri, 1 Nov 2002 15:25:27 +0000 (15:25 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 1 Nov 2002 15:25:27 +0000 (15:25 +0000)
2002-11-01  John Carter  <john.carter@tait.co.nz>

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
libstdc++-v3/include/bits/basic_string.tcc

index ec6a1f5fa4a7f311e9d65fc0b8a6e65a89d7a623..0bf34cbaef08215808397deaba3285d63b023ef2 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-01  John Carter  <john.carter@tait.co.nz>
+
+       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  <hp@bitrange.com>
 
        PR other/3337
index 322528c90aa228197538a58739c9cc64f609c5cb..198f190eae891e754cae476846e995b1cd5caeff 100644 (file)
@@ -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;
     }