From 11a6fedef9dc84e89ee767b8e0ae501f9c447240 Mon Sep 17 00:00:00 2001 From: David Hamilton Date: Thu, 12 Dec 2019 01:20:51 +1300 Subject: [PATCH] Check for nil when loading atomic values This is required to prevent an error when values are loaded without first being set. --- README.md | 1 + candidate_base.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66c20e7..1079c77 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [Chao Yuan](https://github.com/yuanchao0310) * [Jason Maldonis](https://github.com/jjmaldonis) * [Nevio Vesic](https://github.com/0x19) +* [David Hamilton](https://github.com/dihamilton) ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/candidate_base.go b/candidate_base.go index 2d7d664..3e93bbf 100644 --- a/candidate_base.go +++ b/candidate_base.go @@ -194,7 +194,11 @@ func (c *candidateBase) String() string { // LastReceived returns a time.Time indicating the last time // this candidate was received func (c *candidateBase) LastReceived() time.Time { - return c.lastReceived.Load().(time.Time) + lastReceived := c.lastReceived.Load() + if lastReceived == nil { + return time.Time{} + } + return lastReceived.(time.Time) } func (c *candidateBase) setLastReceived(t time.Time) { @@ -204,7 +208,11 @@ func (c *candidateBase) setLastReceived(t time.Time) { // LastSent returns a time.Time indicating the last time // this candidate was sent func (c *candidateBase) LastSent() time.Time { - return c.lastSent.Load().(time.Time) + lastSent := c.lastSent.Load() + if lastSent == nil { + return time.Time{} + } + return lastSent.(time.Time) } func (c *candidateBase) setLastSent(t time.Time) {