$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [interprocess] garbage chars when extending interprocess strings?
From: Anthony Foiani (tkil_at_[hidden])
Date: 2011-07-31 02:39:52
I'm having a peculiar problem with interprocess strings.
0. Create the shared string type.
     typedef boost::interprocess::managed_shared_memory ShmManagerType;
     typedef char ShmCharType;
     typedef boost::interprocess::allocator<
         ShmCharType,
         ShmManagerType::segment_manager
     > ShmCharAllocatorType;
     typedef boost::interprocess::basic_string<
         ShmCharType,
         std::char_traits< ShmCharType >,
         ShmCharAllocatorType
     > ShmStringType;
1. Initial write succeeds.
     ShmStringType val;
     val = "x";
     cout << quoteString( x ) << endl; // prints "x" as expected
2. When I overwrite the value with a longer value, the longer value is
   stored and the length is updated -- but a null character (\0) is
   inserted at the *old* length.
     ShmStringType x3( "xxx" );
     val = x3;
     cout << quoteString( val ) << endl; // prints "x\0x" !!!
3. When I write the longer value again, it is stored correctly and
   there is no \0 in the middle of the string.
     val = x3;
     cout << quoteString( val ) << endl; // prints "xxx" as expected
4. The same thing happens if we try a longer value again:
     ShmStringType x5( "xxxxx" );
     val = x5;
     cout << quoteString( val ) << endl; // prints "xxx\0x"
     val = x5
     cout << quoteString( val ) << endl; // prints "xxxxx"
Does this ring bells for anyone?
On my embedded platform, I'm using:
  powerpc e300c3
  Linux 2.6.36
  eglibc 2.13
  boost 1_44_0
  g++ 4.5.1
And on my development workstation:
  intel x86-64
  Linux 2.6.35.13-92.fc14
  glibc 2.13-1
  boost 1.44.0-8.fc14
  gcc 4.5.1-4.fc14
Testing this on my development workstation, I see similar issues
(although it's not always \0; in this case, I'm getting \xC0 junk
characters.  Odd!)
Test case at:
  http://foiani.com/cpp/boost/InterProcStringTest.cpp
Sample output:
  http://foiani.com/cpp/boost/ipst-out-ppc32.txt
  http://foiani.com/cpp/boost/ipst-out-x86_64.txt
The output isn't the same: some cases work on one platform but not the
other, and the garbage character introduced isn't always \0.
Any ideas would be welcome.
Testing with a more current boost is a bit problematic; if someone
believes that it's been fixed in the mean time, I'll do my best to try
with a modern boost.
In the mean time, I'll just write the values twice, I guess.  :)
Thanks for your time and attention!
Best regards,
Tony