Skip to content

Commit

Permalink
fixed template problem in memory handle serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
csoler committed Jan 25, 2019
1 parent 64b584c commit 3836ed8
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions libretroshare/src/retroshare/rstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,24 @@ struct DirStub : RsSerializable
{
RS_SERIAL_PROCESS(type);
RS_SERIAL_PROCESS(name);
#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // defined(__GNUC__) && !defined(__clang__)
std::uintptr_t& handle(reinterpret_cast<std::uintptr_t&>(ref));
RS_SERIAL_PROCESS(handle);
#if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic pop
#endif // defined(__GNUC__) && !defined(__clang__)

// (Cyril) We have to do this because on some systems (MacOS) uintptr_t is unsigned long which is not well defined. It is always
// preferable to force type serialization to the correct size rather than letting the compiler choose for us.
// /!\ This structure cannot be sent over the network. The serialization would be inconsistent.

if(sizeof(ref) == 4)
{
std::uint32_t& handle(reinterpret_cast<std::uint32_t&>(ref));
RS_SERIAL_PROCESS(handle);
}
else if(sizeof(ref) == 8)
{
std::uint64_t& handle(reinterpret_cast<std::uint64_t&>(ref));
RS_SERIAL_PROCESS(handle);
}
else
std::cerr << __PRETTY_FUNCTION__ << ": cannot serialize raw pointer of size " << sizeof(ref) << std::endl;

}
};

Expand Down

0 comments on commit 3836ed8

Please sign in to comment.