Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
swap_perc: check for division by zero on obsd too
[slstatus.git]
/
components
/
swap.c
diff --git
a/components/swap.c
b/components/swap.c
index
c005691
..
f5db667
100644
(file)
--- a/
components/swap.c
+++ b/
components/swap.c
@@
-76,6
+76,10
@@
}
sscanf(match, "SwapFree: %ld kB\n", &free);
}
sscanf(match, "SwapFree: %ld kB\n", &free);
+ if (total == 0) {
+ return NULL;
+ }
+
return bprintf("%d%%", 100 * (total - free - cached) / total);
}
return bprintf("%d%%", 100 * (total - free - cached) / total);
}
@@
-184,6
+188,10
@@
getstats(&total, &used);
getstats(&total, &used);
+ if (total == 0) {
+ return NULL;
+ }
+
return bprintf("%d%%", 100 * used / total);
}
return bprintf("%d%%", 100 * used / total);
}