This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/7691


Hi,

tested x86-linux, approved by Benjamin.

Ciao, Paolo.

///////////

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.


diff -urN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
--- libstdc++-v3-orig/include/bits/basic_string.tcc	2002-10-27 08:35:06.000000000 +0100
+++ libstdc++-v3/include/bits/basic_string.tcc	2002-11-01 12:14:17.000000000 +0100
@@ -884,9 +884,11 @@
     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;
     }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]