From 78b6b50194b60412117bf2b8a763ab1e8a168f33 Mon Sep 17 00:00:00 2001 From: Matthieu Baerts Date: Fri, 22 May 2015 16:40:12 +0200 Subject: [PATCH] Z1: tmp102: simple: fixed wrong cast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using this code: (int8_t)tmp102_read_temp_x100() / 100 Only the first value is casted into a int8_t type. tmp102_read_temp_x100() returns the temperature in Celcius * 100. Most of the time this value will be lower than -2^7 and higher than 2^7 (+/- 1.27°C). The cast is not needed but a comment about this implicit cast has been added. --- platform/z1/dev/tmp102.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/z1/dev/tmp102.c b/platform/z1/dev/tmp102.c index 11844acb0..cc9394b7b 100644 --- a/platform/z1/dev/tmp102.c +++ b/platform/z1/dev/tmp102.c @@ -185,5 +185,6 @@ tmp102_read_temp_x100(void) int8_t tmp102_read_temp_simple(void) { - return (int8_t)tmp102_read_temp_x100() / 100; + /* Casted to int8_t: We don't expect temperatures outside -128 to 127 C */ + return tmp102_read_temp_x100() / 100; }