Skip to content

Commit f9d6c01

Browse files
committed
Fix incorrect bitshifting in ffi
When a uint8_t is bitshifted to the left, it is actually promoted to an int. For the current code this has the effect of a wrong sign-extension, and the result will also wrongly become zero when insert_pos >= 32. Fix this by adding an explicit cast.
1 parent f673449 commit f9d6c01

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/ffi/ffi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,15 @@ static uint64_t zend_ffi_bit_field_read(void *ptr, zend_ffi_field *field) /* {{{
599599

600600
/* Read full bytes */
601601
while (p < last_p) {
602-
val |= *p++ << insert_pos;
602+
val |= (uint64_t) *p++ << insert_pos;
603603
insert_pos += 8;
604604
}
605605

606606
/* Read partial suffix byte */
607607
if (p == last_p) {
608608
size_t num_bits = last_bit % 8 + 1;
609609
mask = (1U << num_bits) - 1U;
610-
val |= (*p & mask) << insert_pos;
610+
val |= (uint64_t) (*p & mask) << insert_pos;
611611
}
612612

613613
return val;

0 commit comments

Comments
 (0)