Opened 6 years ago
Closed 6 years ago
#12235 closed Bugs (invalid)
boost/endian causes reads from unaligned address.
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | endian |
Version: | Boost 1.61.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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.
Change History (2)
comment:1 by , 6 years ago
Component: | None → endian |
---|---|
Owner: | set to |
comment:2 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
The code you are complaining about is inside this:
so is only reached on machines which permit unaligned loads.
--Beman