Subject: [Boost-bugs] [Boost C++ Libraries] #12235: boost/endian causes reads from unaligned address.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-05-30 16:59:16
#12235: boost/endian causes reads from unaligned address.
-----------------------+------------------------------
Reporter: amotsok@⦠| Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.61.0
Severity: Problem | Keywords:
-----------------------+------------------------------
Example:
{{{
#include <boost/endian/arithmetic.hpp>
int main()
{
char __attribute__ ((aligned (4))) buf[20];
boost::endian::native_int32_t * ptr = (boost::endian::native_int32_t
*)&buf[1];
return ptr->value();
}
}}}
when stepping inside ''boost::endian::native_int32_t::value()'' I see the
code which is doing actual work:
{{{
return *reinterpret_cast<T const *>(bytes);
}}}
where ''bytes'' is argument which corresponds to class member of
''endian_buffer'' which declared as:
{{{
char m_value[n_bits/8];
}}}
In this particular example ''m_value'' gets address ''buf + 1'' and it is
not dividable by four:
{{{
(int)ptr->m_value & 3 == 1
}}}
Not all platforms support reading from unaligned address. This behavior is
dangerous and possibly can cause crashes on those platforms.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12235> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC