patterns: Fix local variables holding larger values than allowed
This commit is contained in:
parent
d399a6427a
commit
6b20a9bdd5
@ -115,6 +115,11 @@ namespace hex {
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr uint64_t bitmask(uint8_t bits) {
|
||||
return (uint64_t(1) << (bits)) - 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T changeEndianess(T value, size_t size, std::endian endian) {
|
||||
if (endian == std::endian::native)
|
||||
|
@ -81,11 +81,11 @@ namespace hex::pl {
|
||||
Token::Literal castedLiteral = std::visit(overloaded {
|
||||
[&](double &value) -> Token::Literal {
|
||||
if (dynamic_cast<PatternDataUnsigned*>(pattern))
|
||||
return u128(value);
|
||||
return u128(value) & bitmask(pattern->getSize() * 8);
|
||||
else if (dynamic_cast<PatternDataSigned*>(pattern))
|
||||
return s128(value);
|
||||
return s128(value) & bitmask(pattern->getSize() * 8);
|
||||
else if (dynamic_cast<PatternDataFloat*>(pattern))
|
||||
return value;
|
||||
return pattern->getSize() == sizeof(float) ? double(float(value)) : value;
|
||||
else
|
||||
LogConsole::abortEvaluation(hex::format("cannot cast type 'double' to type '{}'", pattern->getTypeName()));
|
||||
},
|
||||
@ -103,15 +103,15 @@ namespace hex::pl {
|
||||
},
|
||||
[&](auto &&value) -> Token::Literal {
|
||||
if (dynamic_cast<PatternDataUnsigned*>(pattern) || dynamic_cast<PatternDataEnum*>(pattern))
|
||||
return u128(value);
|
||||
return u128(value) & bitmask(pattern->getSize() * 8);
|
||||
else if (dynamic_cast<PatternDataSigned*>(pattern))
|
||||
return s128(value);
|
||||
return s128(value) & bitmask(pattern->getSize() * 8);
|
||||
else if (dynamic_cast<PatternDataCharacter*>(pattern))
|
||||
return char(value);
|
||||
else if (dynamic_cast<PatternDataBoolean*>(pattern))
|
||||
return bool(value);
|
||||
else if (dynamic_cast<PatternDataFloat*>(pattern))
|
||||
return double(value);
|
||||
return pattern->getSize() == sizeof(float) ? double(float(value)) : value;
|
||||
else
|
||||
LogConsole::abortEvaluation(hex::format("cannot cast integer literal to type '{}'", pattern->getTypeName()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user