aboutsummaryrefslogtreecommitdiffstats
path: root/src/sensor_ldc1612.c
diff options
context:
space:
mode:
authorBevan Weiss <bevanweiss@users.noreply.github.com>2024-08-15 12:14:19 +1000
committerGitHub <noreply@github.com>2024-08-14 22:14:19 -0400
commitc0edfbc4ea02d7d0fb5824a686b4376a05972266 (patch)
tree8c287118e2e50ddba5c910c4d704932a095fcdcc /src/sensor_ldc1612.c
parent3f2ef88eb9f8a24ba870933108b570da616428e2 (diff)
downloadkutter-c0edfbc4ea02d7d0fb5824a686b4376a05972266.tar.gz
kutter-c0edfbc4ea02d7d0fb5824a686b4376a05972266.tar.xz
kutter-c0edfbc4ea02d7d0fb5824a686b4376a05972266.zip
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>
Diffstat (limited to 'src/sensor_ldc1612.c')
-rw-r--r--src/sensor_ldc1612.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/sensor_ldc1612.c b/src/sensor_ldc1612.c
index 01cf3ee0..45e8b84e 100644
--- a/src/sensor_ldc1612.c
+++ b/src/sensor_ldc1612.c
@@ -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