Last active
August 29, 2015 13:58
-
-
Save DonOregano/10116264 to your computer and use it in GitHub Desktop.
Short program demonstrating bug in boost containers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/interprocess/containers/vector.hpp> | |
#include <boost/interprocess/containers/string.hpp> | |
#include <boost/interprocess/managed_shared_memory.hpp> | |
#include <iostream> | |
template <class T> | |
struct VectorShm | |
{ | |
typedef boost::interprocess::allocator<T, boost::interprocess::managed_shared_memory::segment_manager> Allocator; | |
typedef boost::interprocess::vector<T, Allocator> Type; | |
}; | |
typedef boost::interprocess::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> > StringShm; | |
typedef VectorShm<StringShm>::Type StringVectorShm; | |
int main() | |
{ | |
using namespace boost::interprocess; | |
//Create a managed shared memory segment | |
managed_shared_memory segment(open_or_create, "MySharedMemory", 65536); | |
StringVectorShm v(segment.get_segment_manager()); | |
{ | |
StringShm str("OnRevokedRegistration", segment.get_segment_manager()); | |
v.push_back(str); | |
} | |
{ | |
StringShm str("OnCompletedRegistration", segment.get_segment_manager());; | |
v.push_back(str); | |
} | |
{ | |
StringShm str("OnCreateRequest", segment.get_segment_manager());; | |
v.push_back(str); | |
} | |
{ | |
StringShm str("OnUpdateRequest", segment.get_segment_manager());; | |
v.push_back(str); | |
} | |
bool error = false; | |
for(auto& s : v) | |
{ | |
if (strlen(s.c_str()) != s.size()) | |
{ | |
std::cout << "Incorrectly terminated string '" << s.c_str() << "'\n" | |
<< " size() is " << s.size() | |
<< "\n but strlen is " << strlen(s.c_str()) << std::endl; | |
error = true; | |
} | |
} | |
shared_memory_object::remove("MySharedMemory"); | |
if (error) | |
{ | |
std::cout << "Found incorrectly copied/moved string!" << std::endl; | |
} | |
else | |
{ | |
std::cout << "Failed to reproduce error, sorry..." << std::endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8) | |
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11") | |
ADD_EXECUTABLE(container_problem Boost_container_problem.cpp) | |
TARGET_LINK_LIBRARIES(container_problem rt) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://svn.boost.org/trac/boost/ticket/9855