Closed jwilk closed 6 years ago
uint8_t was automatically promoted to int, and then left shift by 24 could overflow it. Add explicit casts to uint32_t to avoid undefined behavior.
uint8_t
int
uint32_t
Is this an issue because on some systems, sizeof(int) == 2?
No, the overflow happens also when sizeof (int) == 4. If buf[0] is ≥ 128, then buf[0] << 24 is ≥ 2147483648, which is greater than INT_MAX.
sizeof (int) == 4
buf[0]
buf[0] << 24
INT_MAX
uint8_t
was automatically promoted toint
, and then left shift by 24 could overflow it. Add explicit casts touint32_t
to avoid undefined behavior.