From 2dd4a033d69af09dd23dd3011ab72af04aea3962 Mon Sep 17 00:00:00 2001 From: Gronpipmaster Date: Wed, 10 Sep 2014 01:23:12 +0700 Subject: [PATCH] Bug fixed division 0 in SwapMemory() --- mem_linux.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mem_linux.go b/mem_linux.go index e9e5ae9..9163a01 100644 --- a/mem_linux.go +++ b/mem_linux.go @@ -55,7 +55,12 @@ func SwapMemory() (*SwapMemoryStat, error) { Free: uint64(sysinfo.Freeswap), } ret.Used = ret.Total - ret.Free - ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0 + //check Infinity + if ret.Total != 0 { + ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0 + } else { + ret.UsedPercent = 0 + } return ret, nil }