[ox/mc] Fix VLI encoding not to chop off ends of >24 bit integers

This commit is contained in:
Gary Talent 2019-03-16 23:52:30 -05:00
parent 1780657789
commit 341dbf14ae

View File

@ -58,7 +58,7 @@ template<typename I>
McInt out; McInt out;
// move input to uint64_t to allow consistent bit manipulation, and to avoid // move input to uint64_t to allow consistent bit manipulation, and to avoid
// overflow concerns // overflow concerns
uint64_t val = *reinterpret_cast<Uint<Bits<I>>*>(&input); uint64_t val = *reinterpret_cast<Unsigned<I>*>(&input);
if (val) { if (val) {
// bits needed to represent number factoring in space possibly // bits needed to represent number factoring in space possibly
// needed for signed bit // needed for signed bit
@ -85,9 +85,11 @@ template<typename I>
LittleEndian<I> leVal = val; LittleEndian<I> leVal = val;
if (bytes == 9) { if (bytes == 9) {
out.data[0] = bytesIndicator; out.data[0] = bytesIndicator;
*reinterpret_cast<I*>(&out.data[1]) = *reinterpret_cast<I*>(&leVal); *reinterpret_cast<I*>(&out.data[1]) = leVal.raw();
} else { } else {
*reinterpret_cast<I*>(&out.data[0]) = (leVal << bytes) | bytesIndicator; *reinterpret_cast<uint64_t*>(&out.data[0]) =
static_cast<uint64_t>(leVal.raw()) << bytes |
static_cast<uint64_t>(bytesIndicator);
} }
out.length = bytes; out.length = bytes;
} }