Skip to content

Commit

Permalink
Merge pull request #134 from svigerske/fix-misaligned-load
Browse files Browse the repository at this point in the history
avoid load of misaligned address warning in BinaryReader
  • Loading branch information
glebbelov authored Mar 22, 2021
2 parents bb7d616 + 791e536 commit 8bfe66e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/mp/nl-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,9 @@ class BinaryReader : private InputConverter, public BinaryReaderBase {
template <typename Int>
Int ReadInt() {
token_ = ptr_;
return this->Convert(*reinterpret_cast<const Int*>(Read(sizeof(Int))));
Int val;
memcpy(&val, Read(sizeof(Int)), sizeof(Int));
return this->Convert(val);
}

int ReadUInt() {
Expand All @@ -1255,8 +1257,9 @@ class BinaryReader : private InputConverter, public BinaryReaderBase {

double ReadDouble() {
token_ = ptr_;
return this->Convert(
*reinterpret_cast<const double*>(Read(sizeof(double))));
double val;
memcpy(&val, Read(sizeof(double)), sizeof(double));
return this->Convert(val);
}

fmt::StringRef ReadString() {
Expand Down

0 comments on commit 8bfe66e

Please sign in to comment.