From 06008c6e81e8d62c3ebf45025448a3137b76d394 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Tue, 2 Nov 2021 12:46:57 +0000 Subject: pipeline: raspberrypi: Fix rounding issue in findBestFormat() The aspect ratio calculation divides two integer values then casts to a double. This might reduce precision when scoring for aspect rato differences. Fix this by casting the integer to a double before the division. Reported-by: Coverity CID=361652 Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Signed-off-by: Kieran Bingham --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 44760093..5e1f2273 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -141,7 +141,7 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size & for (const Size &size : iter.second) { double reqAr = static_cast(req.width) / req.height; - double fmtAr = size.width / size.height; + double fmtAr = static_cast(size.width) / size.height; /* Score the dimensions for closeness. */ score = scoreFormat(req.width, size.width); -- cgit v1.2.1