From de2a5dcd48074fdf08932c9e8e7f38132a1464ee Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Tue, 5 Nov 2019 13:15:36 -0800 Subject: [PATCH] [hardware][interfaces][graphics] fix -Wimplicit-int-float-conversion IEEE 754 single precision cannot precisely represent the value of large 32b integrals. Accept the imprecision from implicit casts by making the casts explicit. One case is comparing the value before and after converting a float to an int32_t and back, the other is used when printing a value. Bug: 139945549 Test: mm Change-Id: Id30edce2cd29c0f9c24cd52ba5fb33f7c56a3100 Signed-off-by: Nick Desaulniers --- .../2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp b/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp index 3d138f7308..5a75ae1591 100644 --- a/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp +++ b/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp @@ -1389,7 +1389,7 @@ static std::string rectString(hwc_rect_t rect) { } static std::string approximateFloatString(float f) { - if (static_cast(f) == f) { + if (static_cast(static_cast(f)) == f) { return std::to_string(static_cast(f)); } int32_t truncated = static_cast(f * 10); @@ -1680,10 +1680,10 @@ std::string HWC2On1Adapter::Display::Config::toString(bool splitLine) const { if (mAttributes.count(HWC2::Attribute::DpiX) != 0 && mAttributes.at(HWC2::Attribute::DpiX) != -1) { std::memset(buffer, 0, BUFFER_SIZE); - writtenBytes = snprintf(buffer, BUFFER_SIZE, - ", DPI: %.1f x %.1f", - mAttributes.at(HWC2::Attribute::DpiX) / 1000.0f, - mAttributes.at(HWC2::Attribute::DpiY) / 1000.0f); + writtenBytes = + snprintf(buffer, BUFFER_SIZE, ", DPI: %.1f x %.1f", + static_cast(mAttributes.at(HWC2::Attribute::DpiX)) / 1000.0f, + static_cast(mAttributes.at(HWC2::Attribute::DpiY)) / 1000.0f); output.append(buffer, writtenBytes); }