diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 3465fa0..c18f2c6 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -1388,11 +1388,11 @@ namespace Proc { for (int i = 0; int v : {(int)round(p.cpu_p), (int)round(p.mem * 100 / Shared::totalMem), (int)p.threads / 3}) { if (proc_gradient) { int val = (min(v, 100) + 100) - calc * 100 / select_max; - if (val < 100) colors[i++] = Theme::g("proc_color").at(val); - else colors[i++] = Theme::g("process").at(val - 100); + if (val < 100) colors[i++] = Theme::g("proc_color").at(max(0, val)); + else colors[i++] = Theme::g("process").at(clamp(val - 100, 0, 100)); } else - colors[i++] = Theme::g("process").at(min(v, 100)); + colors[i++] = Theme::g("process").at(clamp(v, 0, 100)); } c_color = colors.at(0); m_color = colors.at(1); t_color = colors.at(2); } @@ -1401,7 +1401,7 @@ namespace Proc { end = Fx::ub; } if (proc_gradient) { - g_color = Theme::g("proc").at(calc * 100 / select_max); + g_color = Theme::g("proc").at(clamp(calc * 100 / select_max, 0, 100)); } } @@ -1433,9 +1433,10 @@ namespace Proc { if (p.cpu_p < 10 or p.cpu_p >= 100) cpu_str.resize(3); string mem_str = (mem_bytes ? floating_humanizer(p.mem, true) : ""); if (not mem_bytes) { - double mem_p = (double)p.mem * 100 / Shared::totalMem; + double mem_p = clamp((double)p.mem * 100 / Shared::totalMem, 0.0, 100.0); mem_str = to_string(mem_p); - mem_str.resize((mem_p < 10 or mem_p >= 100 ? 3 : 4)); + if (mem_str.size() < 4) mem_str = "0"; + else mem_str.resize((mem_p < 10 or mem_p >= 100 ? 3 : 4)); mem_str += '%'; } out += (thread_size > 0 ? t_color + rjust(to_string(min(p.threads, (size_t)9999)), thread_size) + ' ' + end : "" ) diff --git a/src/btop_theme.cpp b/src/btop_theme.cpp index a912eb2..116e78b 100644 --- a/src/btop_theme.cpp +++ b/src/btop_theme.cpp @@ -159,7 +159,7 @@ namespace Theme { string pre = Fx::e + (depth == "fg" ? "38" : "48") + ";" + (t_to_256 ? "5;" : "2;"); if (hexa.size() == 2) { - int h_int = stoi(hexa, 0, 16); + int h_int = stoi(hexa, nullptr, 16); if (t_to_256) { return pre + to_string(truecolor_to_256(h_int, h_int, h_int)) + "m"; } else { @@ -170,14 +170,14 @@ namespace Theme { else if (hexa.size() == 6) { if (t_to_256) { return pre + to_string(truecolor_to_256( - stoi(hexa.substr(0, 2), 0, 16), - stoi(hexa.substr(2, 2), 0, 16), - stoi(hexa.substr(4, 2), 0, 16))) + "m"; + stoi(hexa.substr(0, 2), nullptr, 16), + stoi(hexa.substr(2, 2), nullptr, 16), + stoi(hexa.substr(4, 2), nullptr, 16))) + "m"; } else { return pre + - to_string(stoi(hexa.substr(0, 2), 0, 16)) + ";" + - to_string(stoi(hexa.substr(2, 2), 0, 16)) + ";" + - to_string(stoi(hexa.substr(4, 2), 0, 16)) + "m"; + to_string(stoi(hexa.substr(0, 2), nullptr, 16)) + ";" + + to_string(stoi(hexa.substr(2, 2), nullptr, 16)) + ";" + + to_string(stoi(hexa.substr(4, 2), nullptr, 16)) + "m"; } } else Logger::error("Invalid size of hex value: " + hexa); @@ -203,14 +203,14 @@ namespace Theme { for (auto& c : hexa) if (not isxdigit(c)) return array{-1, -1, -1}; if (hexa.size() == 2) { - int h_int = stoi(hexa, 0, 16); + int h_int = stoi(hexa, nullptr, 16); return array{h_int, h_int, h_int}; } else if (hexa.size() == 6) { return array{ - stoi(hexa.substr(0, 2), 0, 16), - stoi(hexa.substr(2, 2), 0, 16), - stoi(hexa.substr(4, 2), 0, 16) + stoi(hexa.substr(0, 2), nullptr, 16), + stoi(hexa.substr(2, 2), nullptr, 16), + stoi(hexa.substr(4, 2), nullptr, 16) }; } } @@ -434,4 +434,4 @@ namespace Theme { Fx::reset = Fx::reset_base + Term::fg + Term::bg; } -} \ No newline at end of file +} diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 5eb056e..bb0c944 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1465,7 +1465,7 @@ namespace Proc { if (x-offset < 24) continue; //? Process cpu usage since last update - new_proc.cpu_p = round(cmult * 1000 * (cpu_t - new_proc.cpu_t) / max((uint64_t)1, cputimes - old_cputimes)) / 10.0; + new_proc.cpu_p = clamp(round(cmult * 1000 * (cpu_t - new_proc.cpu_t) / max((uint64_t)1, cputimes - old_cputimes)) / 10.0, 0.0, 100.0 * Shared::coreCount); //? Process cumulative cpu usage since process start new_proc.cpu_c = (double)cpu_t / max(1.0, (uptime * Shared::clkTck) - new_proc.cpu_s);