-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
The code in bmp5.c:
raw_data_t =
(int32_t)((uint32_t)fifo->data[*data_index + 2] << 16 | (uint16_t)fifo->data[*data_index + 1] << 8 |
fifo->data[*data_index]);
does not parse negative numbers correctly. The code reinterprets a uint32_t number as int32_t, relying on the two-complement form of the bytes to match the two-complement representation of int32_t. However, the bytes are 24-bit and not 32-bit, so the two two-complement formats do not coincide for negative numbers.
I have verified that adding these lines afterwards fixes the problem:
if (raw_data_t & 1 << 23) //Check for negative two-complement number
raw_data_t = raw_data_t - (1 << 24);
Metadata
Metadata
Assignees
Labels
No labels