diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2014-06-24 15:30:28 +0000 |
---|---|---|
committer | Martin Kobetic <mkobetic@gmail.com> | 2014-06-24 15:32:04 +0000 |
commit | 32e22b3bb6a5f03977e38513b44b33d3cc1d94e5 (patch) | |
tree | 91cdfabcc88022804b6ecfdb0de35bdc0156d9f0 | |
parent | copy receiver stats in Stats.Sub() (diff) | |
download | dedo-32e22b3bb6a5f03977e38513b44b33d3cc1d94e5.tar.gz dedo-32e22b3bb6a5f03977e38513b44b33d3cc1d94e5.tar.xz |
add some guards for nil pointers
-rw-r--r-- | db.go | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -575,8 +575,15 @@ type Stats struct { // This is useful when obtaining stats at two different points and time and // you need the performance counters that occurred within that time span. func (s *Stats) Sub(other *Stats) Stats { - var diff Stats = *s - diff.TxN = other.TxN - s.TxN + var diff Stats + if s == nil { + return diff + } + diff = *s + if other == nil { + return diff + } + diff.TxN = other.TxN - diff.TxN diff.TxStats = s.TxStats.Sub(&other.TxStats) return diff } |