src: Current code produces warnings for possible value overflows. (#6665)

As the input values are uint8_t types, any shift may result in value loss.
Explicit promotion to the output type (uint32_t) keeps things safe.
Have also changed the int32_t in ads1220_read_adc to uint32_t, type
promotion and bit manipulation are a bit 'weird' on signed integers, so
keep it as an unsigned to align with following function call parameter type.
Have retained the prior explicit sign extension logic however.

Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
This commit is contained in:
Bevan Weiss
2024-08-15 12:14:19 +10:00
committed by GitHub
parent 3f2ef88eb9
commit c0edfbc4ea
3 changed files with 9 additions and 4 deletions

View File

@@ -180,7 +180,10 @@ ldc1612_query(struct ldc1612 *ld, uint8_t oid)
ld->sb.data_count += BYTES_PER_SAMPLE;
// Check for endstop trigger
uint32_t data = (d[0] << 24L) | (d[1] << 16L) | (d[2] << 8) | d[3];
uint32_t data = ((uint32_t)d[0] << 24)
| ((uint32_t)d[1] << 16)
| ((uint32_t)d[2] << 8)
| ((uint32_t)d[3]);
check_home(ld, data);
// Flush local buffer if needed