Boost C++ Libraries: Ticket #13092: Serializing pointer makes sanitizer complain about "reference binding to misaligned address" https://svn.boost.org/trac10/ticket/13092 <p> Consider the following program: </p> <pre class="wiki">#include &lt;memory&gt; #include &lt;sstream&gt; #include &lt;boost/archive/text_iarchive.hpp&gt; #include &lt;boost/archive/text_oarchive.hpp&gt; #include &lt;boost/serialization/shared_ptr.hpp&gt; struct S { int i; char c; template &lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { ar &amp; i; ar &amp; c; } }; int main() { const auto s0 = std::make_shared&lt;S&gt;(); s0-&gt;i = 42; s0-&gt;c = 'c'; std::stringstream ss; { boost::archive::text_oarchive oa(ss); oa &lt;&lt; s0; } std::shared_ptr&lt;S&gt; s1; { boost::archive::text_iarchive ia(ss); ia &gt;&gt; s1; } return 0; } </pre><p> What is important is that we use a pointer to the struct. </p> <p> I then get the following output, which seems to be a real issue probably mitigated by x86's lax requirements on alignment: </p> <pre class="wiki">% g++ -lboost_serialization -fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fno-sanitize=vptr t.cpp&amp;&amp; LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out % LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out /usr/include/boost/archive/detail/iserializer.hpp:540:19: runtime error: reference binding to misaligned address 0x000000000002 for type 'struct S', which requires 4 byte alignment 0x000000000002: note: pointer points here &lt;memory cannot be printed&gt; /usr/include/boost/archive/detail/iserializer.hpp:541:67: runtime error: reference binding to misaligned address 0x000000000002 for type 'const struct S', which requires 4 byte alignment 0x000000000002: note: pointer points here &lt;memory cannot be printed&gt; % LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out % LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libasan.so ./a.out /usr/include/boost/archive/detail/iserializer.hpp:540:19: runtime error: reference binding to misaligned address 0x000000000002 for type 'struct S', which requires 4 byte alignment 0x000000000002: note: pointer points here &lt;memory cannot be printed&gt; /usr/include/boost/archive/detail/iserializer.hpp:541:67: runtime error: reference binding to misaligned address 0x000000000002 for type 'const struct S', which requires 4 byte alignment 0x000000000002: note: pointer points here &lt;memory cannot be printed&gt; </pre><p> Note how it only occurs sometimes, probably depending on what memory address happened to have been returned. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13092 Trac 1.4.3 Robert Ramey Fri, 11 Aug 2017 12:41:00 GMT <link>https://svn.boost.org/trac10/ticket/13092#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13092#comment:1</guid> <description> <p> I can't reproduce this on my system. The best would be if you could send a fix. Note the comment at line 540 of serialization suggests that this problem was foreseen at some point. It's probably caused by something higher in the call stack and a likely fix would be to use some alignment. </p> </description> <category>Ticket</category> </item> </channel> </rss>