1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 07:46:28 +00:00

fix(memory_usage): prevent used swap underflow on windows (#2689)

This commit is contained in:
David Knaack 2021-05-04 17:28:44 +02:00 committed by GitHub
parent 41e417e1d3
commit 6f387769fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,7 +51,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
0 => system.free,
_ => system.avail,
};
let used_memory_kib = system.total - avail_memory_kib;
let used_memory_kib = system.total.saturating_sub(avail_memory_kib);
let total_memory_kib = system.total;
let ram_used = (used_memory_kib as f64 / total_memory_kib as f64) * 100.;
let ram_pct = format_pct(ram_used, pct_sign);
@ -63,7 +63,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let ram = format_usage_total(used_memory_kib, total_memory_kib);
let total_swap_kib = system.swap_total;
let used_swap_kib = system.swap_total - system.swap_free;
let used_swap_kib = system.swap_total.saturating_sub(system.swap_free);
let percent_swap_used = (used_swap_kib as f64 / total_swap_kib as f64) * 100.;
let swap_pct = format_pct(percent_swap_used, pct_sign);
let swap = format_usage_total(used_swap_kib, total_swap_kib);