]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/13650 (string::compare should not (always) use traits_type::length())
authorPaolo Carlini <pcarlini@suse.de>
Sun, 25 Jan 2004 13:13:41 +0000 (13:13 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 25 Jan 2004 13:13:41 +0000 (13:13 +0000)
2004-01-25  Paolo Carlini  <pcarlini@suse.de>

PR libstdc++/13650
* include/bits/basic_string.tcc (compare(size_type, size_type,
const _CharT*, size_type)): Implement correctly the resolution
of DR 5: basically, s is a char array, -not- a C string.

* include/bits/basic_string.tcc (_M_clone): Null-terminate.

From-SVN: r76555

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.tcc

index 5df60196bc6578d47062e7bffa6824587e7fc531..a1e5a00312516e7b86647dfe5a32b145942c6e1f 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-25  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/13650
+       * include/bits/basic_string.tcc (compare(size_type, size_type,
+       const _CharT*, size_type)): Implement correctly the resolution
+       of DR 5: basically, s is a char array, -not- a C string.
+
+       * include/bits/basic_string.tcc (_M_clone): Null-terminate.
+
 2004-01-19  Paolo Carlini  <pcarlini@suse.de>
 
        PR libstdc++/12352
index d3f1e8e3605905ea645f67be6a8d3da65ddcbfef..d5fc337ecabfce4b39a8afc278ecdf40da2f03ac 100644 (file)
@@ -592,6 +592,7 @@ namespace std
            }
        }
       __r->_M_length = _M_length;
+      __r->_M_refdata()[_M_length] = _Rep::_S_terminal;
       return __r->_M_refdata();
     }
   
@@ -1033,12 +1034,11 @@ namespace std
       if (__pos > __size)
        __throw_out_of_range("basic_string::compare");
       
-      size_type __osize = std::min(traits_type::length(__s), __n2);
       size_type __rsize = std::min(size_type(__size - __pos), __n1);
-      size_type __len = std::min(__rsize, __osize);
+      size_type __len = std::min(__rsize, __n2);
       int __r = traits_type::compare(_M_data() + __pos, __s, __len);
       if (!__r)
-       __r = __rsize - __osize;
+       __r = __rsize - __n2;
       return __r;
     }