public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/67503] New: String cannot be loaded from binary representation
@ 2015-09-08 16:28 radventure at yandex dot ru
  2015-09-08 16:32 ` [Bug libstdc++/67503] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 16:28 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-09-08 17:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
2015-09-08 16:32 ` [Bug libstdc++/67503] " redi at gcc dot gnu.org
2015-09-08 16:40 ` pinskia at gcc dot gnu.org
2015-09-08 16:54 ` radventure at yandex dot ru
2015-09-08 16:56 ` radventure at yandex dot ru
2015-09-08 17:03 ` redi at gcc dot gnu.org
2015-09-08 17:05 ` radventure at yandex dot ru
2015-09-08 17:08 ` radventure at yandex dot ru
2015-09-08 17:09 ` pinskia at gcc dot gnu.org
2015-09-08 17:12 ` pinskia at gcc dot gnu.org
2015-09-08 17:15 ` radventure at yandex dot ru
2015-09-08 17:25 ` radventure at yandex dot ru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).