Skip to content

Commit

Permalink
fixup! Clean up the erts_bs_get_integer_2() function in erl_bits.c
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Oct 27, 2024
1 parent 718b302 commit e5c0a80
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions erts/emulator/beam/erl_bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ erts_bs_get_integer_2(Process *p, Uint num_bits,

byte_offset = BYTE_OFFSET(sb->start);
bp = erl_sub_bits_get_base(sb) + byte_offset;
offs = BIT_OFFSET(sb->start);

/*
* Special cases for field sizes up to the size of Uint.
*/

if (num_bits <= 8-(offs = BIT_OFFSET(sb->start))) {
if (num_bits <= 8 - offs) {
/*
* All bits are in one byte in the binary. We only need
* shift them right and mask them.
Expand All @@ -239,10 +240,9 @@ erts_bs_get_integer_2(Process *p, Uint num_bits,
* mask to extract the bits.
*/
Uint w = bp[0] << 8 | bp[1];
Uint mask = MAKE_MASK(num_bits);
sb->start += num_bits;
w >>= 16 - offs - num_bits;
w &= mask;
w &= MAKE_MASK(num_bits);
MAYBE_SIGN_EXTEND(flags, w, num_bits);
return make_small(w);
} else if (num_bits < SMALL_BITS && (flags & BSF_LITTLE) == 0) {
Expand Down

0 comments on commit e5c0a80

Please sign in to comment.