From 22ace7c41b8b54fd3dc592984211d7e61350bcce Mon Sep 17 00:00:00 2001 From: Mathis Engelbart Date: Mon, 10 Aug 2026 10:03:07 +0200 Subject: [PATCH] Fix divide by 0 and remove unused variable --- gcc/loss_rate_controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/loss_rate_controller.go b/gcc/loss_rate_controller.go index 249d733..16e1d6f 100644 --- a/gcc/loss_rate_controller.go +++ b/gcc/loss_rate_controller.go @@ -8,7 +8,6 @@ type lossRateController struct { min, max float64 packetsSinceLastUpdate int - arrivedSinceLastUpdate int lostSinceLastUpdate int } @@ -18,14 +17,12 @@ func newLossRateController(initialRate, minRate, maxRate int) *lossRateControlle min: float64(minRate), max: float64(maxRate), packetsSinceLastUpdate: 0, - arrivedSinceLastUpdate: 0, lostSinceLastUpdate: 0, } } func (l *lossRateController) onPacketAcked() { l.packetsSinceLastUpdate++ - l.arrivedSinceLastUpdate++ } func (l *lossRateController) onPacketLost() { @@ -34,6 +31,10 @@ func (l *lossRateController) onPacketLost() { } func (l *lossRateController) update(lastDeliveryRate int) int { + // Without any reported packets there is no loss rate to act on. + if l.packetsSinceLastUpdate == 0 { + return l.bitrate + } lossRate := float64(l.lostSinceLastUpdate) / float64(l.packetsSinceLastUpdate) var target float64 if lossRate > 0.1 { @@ -56,7 +57,6 @@ func (l *lossRateController) update(lastDeliveryRate int) int { } l.packetsSinceLastUpdate = 0 - l.arrivedSinceLastUpdate = 0 l.lostSinceLastUpdate = 0 return l.bitrate