From 0e7c08ba1549fddb4d5a9314e0bd6a407e7ff109 Mon Sep 17 00:00:00 2001 From: "romolo.manfredini@gmail.com" Date: Mon, 20 Aug 2012 23:27:56 +0000 Subject: [PATCH] Fix overflow in calculations --- src/frsky.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frsky.cpp b/src/frsky.cpp index 3d8db237b..a30e67b77 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -137,7 +137,7 @@ typedef enum { int16_t applyChannelRatio(uint8_t channel, int16_t val) { - return ((int16_t)val+g_model.frsky.channels[channel].offset) * (g_model.frsky.channels[channel].ratio << g_model.frsky.channels[channel].multiplier) * 2 / 51; + return (int16_t)(((int32_t)val+g_model.frsky.channels[channel].offset) * (g_model.frsky.channels[channel].ratio << g_model.frsky.channels[channel].multiplier) * 2 / 51); } void evalVario(int16_t altitude_bp, uint16_t altitude_ap)