From daedbd7e47e77b6c6d0dc9668176b4e93d6f6760 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Tue, 5 Nov 2019 13:15:36 -0800 Subject: [PATCH 1/3] [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: I23375d73cd16be0741defc6395046bd3b22d1335 Merged-in: 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); } From 890faa2ac5a344ad49fee68634695bc6fb957d39 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Tue, 5 Nov 2019 14:55:47 -0800 Subject: [PATCH 2/3] [hardware][interfaces][sensors] fix -Wreorder-init-list again C++20 will require members in a designated initializer to be in order unlike C99. This snuck in because I haven't upgraded the platform toolchain yet. Bug: 139945549 Test: mm Change-Id: Id121ecd46b7e53f5dd7b4a32daae0594d851d0e5 Merged-in: Ica2844a213467e41d9b6a8955f1750692da8b444 Signed-off-by: Nick Desaulniers --- sensors/common/vts/utils/GrallocWrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensors/common/vts/utils/GrallocWrapper.cpp b/sensors/common/vts/utils/GrallocWrapper.cpp index 1cad9135b7..e63faa2e1c 100644 --- a/sensors/common/vts/utils/GrallocWrapper.cpp +++ b/sensors/common/vts/utils/GrallocWrapper.cpp @@ -147,8 +147,8 @@ BufferDescriptor GrallocHalWrapper::getDescriptor(uint32_t .width = size, .height = 1, .layerCount = 1, - .usage = kBufferUsage, .format = static_cast(PixelFormat::BLOB), + .usage = kBufferUsage, }; BufferDescriptor descriptor; From 8cb3c9b3265686cf8c47beb27e7aa99e0d4f0729 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Tue, 5 Nov 2019 14:56:57 -0800 Subject: [PATCH 3/3] [hardware][interfaces][sensors] fix -Wreorder-init-list C++20 will require members in a designated initializer to be in order unlike C99. Bug: 139945549 Test: mm Merged-In: I78d64ea2b7df3f2bd3b8503aa553a0523b20d711 Change-Id: I8a7ff4b025ac693398b79ad5f16687afe3a4c5a9 Signed-off-by: Nick Desaulniers --- sensors/1.0/default/convert.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sensors/1.0/default/convert.cpp b/sensors/1.0/default/convert.cpp index 52f5e4f5a0..53ceb0d92f 100644 --- a/sensors/1.0/default/convert.cpp +++ b/sensors/1.0/default/convert.cpp @@ -68,9 +68,9 @@ void convertFromSensorEvent(const sensors_event_t &src, Event *dst) { typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType; *dst = { - .sensorHandle = src.sensor, - .sensorType = (SensorType)src.type, - .timestamp = src.timestamp + .timestamp = src.timestamp, + .sensorHandle = src.sensor, + .sensorType = (SensorType)src.type, }; switch (dst->sensorType) {