1
0
mirror of synced 2024-11-28 09:30:51 +01:00

fix: Some occurrences of undefined behaviour

This commit is contained in:
WerWolv 2022-08-15 21:08:09 +02:00
parent fb2af5593f
commit 6b62a1963e
2 changed files with 3 additions and 3 deletions

View File

@ -68,7 +68,7 @@ namespace hex {
}
constexpr inline i128 signExtend(size_t numBits, i128 value) {
i128 mask = 1U << (numBits - 1);
i128 mask = 1ULL << (numBits - 1);
return (value ^ mask) - mask;
}

View File

@ -86,7 +86,7 @@ namespace hex::plugin::builtin {
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? hex::format("0x{{0:0{}X}}", Size * 2) : hex::format("0o{{0:0{}o}}", Size * 3));
T value = 0x00;
std::memcpy(&value, buffer.data(), Size);
std::memcpy(&value, buffer.data(), std::min(sizeof(T), Size));
return hex::format(format, hex::changeEndianess(value, Size, endian));
}
@ -98,7 +98,7 @@ namespace hex::plugin::builtin {
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? hex::format("{{0}}0x{{1:0{}X}}", Size * 2) : hex::format("{{0}}0o{{1:0{}o}}", Size * 3));
T value = 0x00;
std::memcpy(&value, buffer.data(), Size);
std::memcpy(&value, buffer.data(), std::min(sizeof(T), Size));
auto number = hex::signExtend(Size * 8, hex::changeEndianess(value, Size, endian));
bool negative = number < 0;