Skip to content

Commit 36120c2

Browse files
committed
vl53l0x: Cast unsigned abs param to signed type to fix clang warning
FixPoint1616_t is typedef'd to uint32_t. The result of dividing two variables of that type is also unsigned. Passing an unsigned value to abs doesn't make sense. Cast the value to int32_t in case the computaton of diff1_mcps generates a negative result so that xTalkCorrection doesn't end up with a huge value. Signed-off-by: Keith Packard <keithp@keithp.com>
1 parent cccbc24 commit 36120c2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

sensor/vl53l0x/README

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@ License:
4949
License Link:
5050
http://www.st.com/en/embedded-software/stsw-img005.html
5151

52+
Patch List:
5253

53-
54+
*Cast unsigned abs param to signed type
55+
This will prevent a compiler warning when using clang
56+
without -ffreestanding
57+
Impacted files:
58+
api/core/src/vl53l0x_api_core.c

sensor/vl53l0x/api/core/src/vl53l0x_api_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ VL53L0X_Error VL53L0X_calc_sigma_estimate(VL53L0X_DEV Dev,
18721872
diff1_mcps <<= 8;
18731873

18741874
/* FixPoint0824/FixPoint1616 = FixPoint2408 */
1875-
xTalkCorrection = abs(diff1_mcps/diff2_mcps);
1875+
xTalkCorrection = abs((int32_t) (diff1_mcps/diff2_mcps));
18761876

18771877
/* FixPoint2408 << 8 = FixPoint1616 */
18781878
xTalkCorrection <<= 8;

0 commit comments

Comments
 (0)