Ensure the current average rate calculation can't accidentally divide by zero.

This commit is contained in:
Andrew Wood
2025-07-26 20:53:22 +01:00
parent 870dfad9fd
commit 3bd49a0c3f
+3
View File
@@ -59,6 +59,9 @@ static void pv__update_average_rate_history(pvtransfercalc_t calc, readonly_pvtr
} else {
off_t bytes = (calc->history[last].transferred - calc->history[first].transferred);
long double sec = (calc->history[last].elapsed_sec - calc->history[first].elapsed_sec);
/* Safety check to avoid division by zero. */
if (sec < 0.000001 && sec > -0.000001)
sec = 0.000001;
calc->current_avg_rate = (long double) bytes / sec;
}
}