[Bug libstdc++/67503] New: String cannot be loaded from binary representation

radventure at yandex dot ru gcc-bugzilla@gcc.gnu.org
Tue Sep 8 16:28:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67503

            Bug ID: 67503
           Summary: String cannot be loaded from binary representation
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: radventure at yandex dot ru
  Target Milestone: ---

#include <iostream>
#include <string>

int main() {
  unsigned char buff1[sizeof(std::string)], buff2[sizeof(std::string)];
  std::string s1("SMAL STRING BUG"), s2;
  new (&buff1) std::string(s1);
  s2 = *(reinterpret_cast<std::string*>(&buff1));
  std::cout << s2 << std::endl;
  std::swap(buff1, buff2);
  s2 = *(reinterpret_cast<std::string*>(&buff2));
  std::cout << s2 << std::endl;
}

After swapping buffers _N_dataplus._M_p pointer points into we buff1 but actual
data stored in small local buffer was coped correctly. If initial string length
will be greater when data will be stored into the heap and everything will be
Ok.



More information about the Gcc-bugs mailing list