From 930c65e7c3328cd7c63000e3f9ef04b783514f0b Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Sun, 1 Jan 2023 23:37:20 +0100 Subject: [PATCH] UI: Prevent negative "disk full in" calculation when no output If the output is paused the average bitrate will be zero, resulting in infinite time until disk is full and int overflows. Similarly, if no data has been collected yet, the result will be NaN and undefined behavior. --- UI/window-basic-stats.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UI/window-basic-stats.cpp b/UI/window-basic-stats.cpp index 7f5986a0e..dd05bdf38 100644 --- a/UI/window-basic-stats.cpp +++ b/UI/window-basic-stats.cpp @@ -452,9 +452,15 @@ void OBSBasicStats::ResetRecTimeLeft() void OBSBasicStats::RecordingTimeLeft() { + if (bitrates.empty()) + return; + long double averageBitrate = accumulate(bitrates.begin(), bitrates.end(), 0.0) / (long double)bitrates.size(); + if (averageBitrate == 0) + return; + long double bytesPerSec = (averageBitrate / 8.0l) * 1000.0l; long double secondsUntilFull = (long double)num_bytes / bytesPerSec;