Skip to content

Commit

Permalink
#1839: use memcpy to bitcast back to a signed type
Browse files Browse the repository at this point in the history
  • Loading branch information
nmm0 committed Jun 1, 2022
1 parent 5cee0b5 commit f431e16
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/vt/utils/bits/bits_packer.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ BitPacker::setFieldDynamic(
UnsignedBitField seg;
// Static cast will not work for negative types if we end up with that
std::memcpy(&seg, &segment, sizeof(UnsignedBitField));
auto bits = static_cast<BitField>(((seg << nbits) >> nbits) << start);
field = field | bits;
auto bits = ((seg << nbits) >> nbits) << start;
BitField field_bits;
std::memcpy(&field_bits, &bits, sizeof(BitField));
field = field | field_bits;
}

template <FieldType start, FieldType len, typename BitField>
Expand Down

0 comments on commit f431e16

Please sign in to comment.