diff --git a/src/detection/battery/battery_android.c b/src/detection/battery/battery_android.c index 7b3a2e084..6ddf3bbfe 100644 --- a/src/detection/battery/battery_android.c +++ b/src/detection/battery/battery_android.c @@ -71,6 +71,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results) FFBatteryResult* battery = ffListAdd(results); battery->temperature = FF_BATTERY_TEMP_UNSET; + battery->cycleCount = 0; ffStrbufInit(&battery->manufacturer); ffStrbufInit(&battery->modelName); ffStrbufInit(&battery->status); diff --git a/src/detection/battery/battery_apple.c b/src/detection/battery/battery_apple.c index 602a61fc7..213cef853 100644 --- a/src/detection/battery/battery_apple.c +++ b/src/detection/battery/battery_apple.c @@ -56,7 +56,9 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) ffStrbufAppendS(&battery->modelName, "Built-in"); } - ffCfDictGetInt(properties, CFSTR("CycleCount"), (int32_t*) &battery->cycleCount); + int32_t cycleCount = 0; + ffCfDictGetInt(properties, CFSTR("CycleCount"), &cycleCount); + battery->cycleCount = cycleCount < 0 ? 0 : (uint32_t) cycleCount; if (!ffCfDictGetBool(properties, CFSTR("ExternalConnected"), &boolValue) && boolValue) ffStrbufAppendS(&battery->status, "AC connected, "); diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 426d2731f..49daded72 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -75,8 +75,12 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option ffReadFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufTrimRightSpace(&testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); - if(dir->length) - result->cycleCount = (uint32_t) ffStrbufToUInt(&testBatteryBuffer, 0); + if (dir->length) + { + int64_t cycleCount = 0; + cycleCount = (int64_t) strtoll(testBatteryBuffer.chars, NULL, 10); + result->cycleCount = cycleCount < 0 || cycleCount > UINT32_MAX ? 0 : (uint32_t) cycleCount; + } result->temperature = FF_BATTERY_TEMP_UNSET; if (options->temp) diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index 283ccc135..9deea532c 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -150,7 +150,7 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF ffStrbufInit(&battery->manufacturer); ffStrbufInit(&battery->technology); ffStrbufInit(&battery->status); - battery->temperature = 0.0/0.0; + battery->temperature = FF_BATTERY_TEMP_UNSET; battery->cycleCount = 0; battery->capacity = info.RemainingCapacity * 100.0 / info.MaxCapacity;