1
0
mirror of https://github.com/libretro/RetroArch synced 2025-02-28 22:13:51 +00:00

Merge pull request from Jamiras/http_task_progress_div_zero

prevent divide by zero error when calculating http transfer percentage
This commit is contained in:
Twinaphex 2020-01-23 01:57:15 +01:00 committed by GitHub
commit b0aa447d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -126,7 +126,14 @@ static int task_http_iterate_transfer(retro_task_t *task)
if (!net_http_update(http->handle, &pos, &tot))
{
task_set_progress(task, (tot == 0) ? -1 : (signed)pos / (tot / 100));
if (tot == 0)
task_set_progress(task, -1);
else if (pos < (((size_t)-1) / 100))
/* prefer multiply then divide for more accurate results */
task_set_progress(task, (signed)(pos * 100 / tot));
else
/* but invert the logic if it would cause an overflow */
task_set_progress(task, MAX((signed)pos / (tot / 100), 100));
return -1;
}