Check for nil when loading atomic values

This is required to prevent an error when values are loaded
without first being set.
This commit is contained in:
David Hamilton
2019-12-12 01:20:51 +13:00
parent 57e7b93a4b
commit 11a6fedef9
2 changed files with 11 additions and 2 deletions
+1
View File
@@ -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
+10 -2
View File
@@ -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) {