This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]