http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54392
--- Comment #8 from Michael Haubenwallner <michael.haubenwallner at salomon dot
at> 2012-08-29 15:20:50 UTC ---
Actually, valgrind does show an "Invalid write of size 1" for this testcase,
unrelated to the default string at all:
{
std::string s1 = "a";
s1.assign(s1.c_str(), 2);
}
So I'm proposing this fix here:
--- basic_string.tcc.orig 2012-08-29 17:12:53.349220855 +0200
+++ basic_string.tcc 2012-08-29 17:13:37.021326394 +0200
@@ -262,7 +262,7 @@
{
__glibcxx_requires_string_len(__s, __n);
_M_check_length(this->size(), __n, "basic_string::assign");
- if (_M_disjunct(__s) || _M_rep()->_M_is_shared())
+ if (_M_disjunct(__s) || _M_rep()->_M_is_shared() || this->size() < __n)
return _M_replace_safe(size_type(0), this->size(), __s, __n);
else
{