From feedda1d84e11f3b80ae076400531ab8a9eadacb Mon Sep 17 00:00:00 2001 From: Demon000 Date: Fri, 6 Sep 2019 13:47:29 +0200 Subject: [PATCH] davinci: light: Avoid uint32_t underflow Change-Id: If4f9360cc301ee8ba9f432dbbe3379c2c634c574 --- light/Light.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/light/Light.cpp b/light/Light.cpp index 44507f4..f16c82a 100644 --- a/light/Light.cpp +++ b/light/Light.cpp @@ -74,6 +74,10 @@ static uint32_t getBrightness(const LightState& state) { } static inline uint32_t scaleBrightness(uint32_t brightness, uint32_t maxBrightness) { + if (brightness == 0) { + return 0; + } + return (brightness - 1) * (maxBrightness - 1) / (0xFF - 1) + 1; }