Remove undefined behaviour from literal number
This commit is contained in:
parent
b23716087a
commit
88191480a8
1 changed files with 6 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "operand.h"
|
#include "operand.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
#include <cstring>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
|
|
||||||
namespace Sirit {
|
namespace Sirit {
|
||||||
|
@ -26,18 +27,15 @@ class LiteralNumber : public Operand {
|
||||||
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
static_assert(sizeof(T) == 4 || sizeof(T) == 8);
|
||||||
|
|
||||||
LiteralNumber* number = new LiteralNumber(std::type_index(typeid(T)));
|
LiteralNumber* number = new LiteralNumber(std::type_index(typeid(T)));
|
||||||
if (number->is_32 = sizeof(T) == 4; number->is_32) {
|
number->is_32 = sizeof(T) == 4;
|
||||||
number->raw = *reinterpret_cast<u32*>(&value);
|
std::memcpy(&number->raw, &value, sizeof(T));
|
||||||
} else {
|
|
||||||
number->raw = *reinterpret_cast<u64*>(&value);
|
|
||||||
}
|
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::type_index type;
|
std::type_index type;
|
||||||
bool is_32;
|
bool is_32{};
|
||||||
u64 raw;
|
u64 raw{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Sirit
|
} // namespace Sirit
|
||||||
|
|
Loading…
Reference in a new issue