From 66ed7903f08bf9d8cbc35b612041ccb48e7de0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrianna=20Pi=C5=84ska?= Date: Sat, 20 Apr 2024 21:29:54 +0200 Subject: [PATCH 1/2] Handle special case of min and max CPU frequency being exual to avoid dividing by zero --- src/powerkit_cpu.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/powerkit_cpu.cpp b/src/powerkit_cpu.cpp index f392e42..101154f 100644 --- a/src/powerkit_cpu.cpp +++ b/src/powerkit_cpu.cpp @@ -427,7 +427,12 @@ const QPair Cpu::getCpuFreqLabel() int freqMin = Cpu::getMinFrequency(); int freqMax = Cpu::getMaxFrequency(); - int progress = ((currentCpuFreq - freqMin) * 100) / (freqMax - freqMin); + int progress; + if (freqMax > freqMin) { + progress = ((currentCpuFreq - freqMin) * 100) / (freqMax - freqMin); + } else { + progress = 100; + } result.first = progress; result.second = QString("%1\nGhz").arg(QString::number(currentFancyFreq / 1000000, 'f', 2)); From b5262d6443b533e94ea7c1bd3c60aaf108a32d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrianna=20Pi=C5=84ska?= Date: Sat, 20 Apr 2024 21:48:03 +0200 Subject: [PATCH 2/2] Rewrite the logic to avoid affecting cases where max < min for some reason; bad configuration should not be masked --- src/powerkit_cpu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/powerkit_cpu.cpp b/src/powerkit_cpu.cpp index 101154f..a2a604c 100644 --- a/src/powerkit_cpu.cpp +++ b/src/powerkit_cpu.cpp @@ -428,10 +428,10 @@ const QPair Cpu::getCpuFreqLabel() int freqMin = Cpu::getMinFrequency(); int freqMax = Cpu::getMaxFrequency(); int progress; - if (freqMax > freqMin) { - progress = ((currentCpuFreq - freqMin) * 100) / (freqMax - freqMin); - } else { + if (freqMax == freqMin) { progress = 100; + } else { + progress = ((currentCpuFreq - freqMin) * 100) / (freqMax - freqMin); } result.first = progress;