Fixes Undefined Behavior in LaneTupel (Strict Aliasing), resolves 2665
It's complicated :sigh: read this please:
http://dbp-consulting.com/tutorials/StrictAliasing.html
tl;dr: has to go through a memcpy (in C++) as in:
184cc11cee/src/support/utilities.h (L29-L40)
This commit is contained in:
parent
50cbba1620
commit
130d5298fc
@ -2,6 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
@ -24,10 +25,8 @@ LaneTupel::LaneTupel(const LaneID lanes_in_turn, const LaneID first_lane_from_th
|
||||
// comparation based on interpretation as unsigned 32bit integer
|
||||
bool LaneTupel::operator==(const LaneTupel other) const
|
||||
{
|
||||
static_assert(sizeof(LaneTupel) == sizeof(std::uint16_t),
|
||||
"Comparation requires LaneTupel to be the of size 16Bit");
|
||||
return *reinterpret_cast<const std::uint16_t *>(this) ==
|
||||
*reinterpret_cast<const std::uint16_t *>(&other);
|
||||
return std::tie(lanes_in_turn, first_lane_from_the_right) ==
|
||||
std::tie(other.lanes_in_turn, other.first_lane_from_the_right);
|
||||
}
|
||||
|
||||
bool LaneTupel::operator!=(const LaneTupel other) const { return !(*this == other); }
|
||||
@ -35,10 +34,8 @@ bool LaneTupel::operator!=(const LaneTupel other) const { return !(*this == othe
|
||||
// comparation based on interpretation as unsigned 32bit integer
|
||||
bool LaneTupel::operator<(const LaneTupel other) const
|
||||
{
|
||||
static_assert(sizeof(LaneTupel) == sizeof(std::uint16_t),
|
||||
"Comparation requires LaneTupel to be the of size 16Bit");
|
||||
return *reinterpret_cast<const std::uint16_t *>(this) <
|
||||
*reinterpret_cast<const std::uint16_t *>(&other);
|
||||
return std::tie(lanes_in_turn, first_lane_from_the_right) <
|
||||
std::tie(other.lanes_in_turn, other.first_lane_from_the_right);
|
||||
}
|
||||
|
||||
} // namespace guidance
|
||||
|
Loading…
Reference in New Issue
Block a user