[RFC] First 3.5 project: don't assign _S_terminal in string::c_str()

Paolo Carlini pcarlini@suse.de
Sat Jan 17 14:52:00 GMT 2004


Paolo Carlini wrote:

> in the current basic_string implementation we are quite careful
> in keeping the internal representation null-terminated: I have
> spotted only one place which should be fixed: _M_clone.

By the way, due to 21.3.4 this is a *bug*, that we should fix in
3.4 (3.3?) too. Testcase:

#include <string>
#include <cassert>

int main()
{
  std::string a;

  for (int i = 0; i < 5000; ++i)
    a += 'a';

  a.reserve(5100);

  const std::string b(a);
 
  char ch = b[5000];

  assert( ch == '\0' );
}

Paolo.



More information about the Libstdc++ mailing list