title: std::string::assign() causes segfault
body: <p>I have a <code>std::vector&lt;uint8_t&gt;</code> that contains strings at specific offsets. Here's a shortened dump:</p>
  
  <pre><code>...
  @128    00 00 00 00 00 00 00 00 73 6F 6D 65 74 68 69 33 ........somethin
  @144    38 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ng..............
  @160    00 00 00 00 00 00 00 00 31 2E 32 2E 33 00 00 00 ........1.2.3...
  @176    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  ...
  </code></pre>
  
  <p>I am trying to extract the data at offset 136 and put it into a <code>std::string</code>:</p>
  
  <pre><code>std::string x;
  x.assign(vec.begin()+136, vec.begin()+168);
  </code></pre>
  
  <p>This however, causes my application to segfault. Now I'm pretty new at software development under Linux, but I do know how to start my app in GDB and get a backtrace, and tracked the problem down here:</p>
  
  <pre><code>(gdb) backtrace
  #0  0xb7536d78 in ?? () from /lib/i686/cmov/libc.so.6
  #1  0xb7538cd5 in malloc () from /lib/i686/cmov/libc.so.6
  #2  0xb7708957 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6
  #3  0xb76e4146 in std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator&lt;char&gt; const&amp;) () from /usr/lib/libstdc++.so.6
  #4  0xb76e63b0 in std::string::_M_mutate(unsigned int, unsigned int, unsigned int) () from /usr/lib/libstdc++.so.6
  #5  0xb76e654a in std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) () from /usr/lib/libstdc++.so.6
  #6  0x0806d651 in std::string::_M_replace_dispatch&lt;__gnu_cxx::__normal_iterator&lt;unsigned char const*, std::vector&lt;unsigned char, std::allocator&lt;unsigned char&gt; &gt; &gt; &gt; (this=0xbfffe464, __i1=..., __i2=..., __k1=..., __k2=...) at /usr/include/c++/4.3/bits/basic_string.tcc:637
  #7  0x0806d26e in std::string::replace&lt;__gnu_cxx::__normal_iterator&lt;unsigned char const*, std::vector&lt;unsigned char, std::allocator&lt;unsigned char&gt; &gt; &gt; &gt; (this=0x811c730, vec=...) at /usr/include/c++/4.3/bits/basic_string.h:1390
  #8  std::string::assign&lt;__gnu_cxx::__normal_iterator&lt;unsigned char const*, std::vector&lt;unsigned char, std::allocator&lt;unsigned char&gt; &gt; &gt; &gt; (
      this=0x811c730, vec=...) at /usr/include/c++/4.3/bits/basic_string.h:958
  #9  myclass::somemethod (this=0x811c730, vec=...) at myclass.cpp:135
  </code></pre>
  
  <p>Printing <code>vec.size()</code> returns 200 and even looping over the vector and printing the data causes me no problems (exactly above the crashing snippet!).</p>
  
  <p>I am compiling in Debian with g++ 4.3.4. Any pointers on what this problem could be?</p>