From 808e57e3f3af403f45d44c93da2e275d427f30cf Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Fri, 2 Mar 2018 11:27:02 -0500 Subject: [PATCH] healthd: Fix negativity check after cast to unsigned enum mapSysfsString return code is checked for negativity after being casted to unsigned enum type, which will always be false. This is obviously unintended behaviour. Fixes tautological-unsigned-enum-zero-compare warning. Bug: 72331526 Test: m Change-Id: Icec76d7a1121cb56fd9d05feb70cede69954c322 --- healthd/BatteryMonitor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 08b8b269d..fa79d0bb2 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -143,7 +143,7 @@ int BatteryMonitor::readFromFile(const String8& path, std::string* buf) { BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String8& path) { std::string buf; - BatteryMonitor::PowerSupplyType ret; + int ret; struct sysfsStringEnumMap supplyTypeMap[] = { { "Unknown", ANDROID_POWER_SUPPLY_TYPE_UNKNOWN }, { "Battery", ANDROID_POWER_SUPPLY_TYPE_BATTERY }, @@ -164,13 +164,13 @@ BatteryMonitor::PowerSupplyType BatteryMonitor::readPowerSupplyType(const String if (readFromFile(path, &buf) <= 0) return ANDROID_POWER_SUPPLY_TYPE_UNKNOWN; - ret = (BatteryMonitor::PowerSupplyType)mapSysfsString(buf.c_str(), supplyTypeMap); + ret = mapSysfsString(buf.c_str(), supplyTypeMap); if (ret < 0) { KLOG_WARNING(LOG_TAG, "Unknown power supply type '%s'\n", buf.c_str()); ret = ANDROID_POWER_SUPPLY_TYPE_UNKNOWN; } - return ret; + return static_cast(ret); } bool BatteryMonitor::getBooleanField(const String8& path) {