Prevent integer div by 0 in curl progress callback
If the curl callback is called at the exact same time as the download begins, this callback would cause an integer division by zero.
This commit is contained in:
parent
007f09edc3
commit
7a0949b99c
1 changed files with 14 additions and 1 deletions
|
|
@ -1766,12 +1766,25 @@ size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||||
|
|
||||||
int curlprogress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
int curlprogress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||||
{
|
{
|
||||||
|
time_t curtime;
|
||||||
|
|
||||||
(void)clientp;
|
(void)clientp;
|
||||||
(void)ultotal;
|
(void)ultotal;
|
||||||
(void)ulnow; // Function prototype requires these but we won't use, so just discard
|
(void)ulnow; // Function prototype requires these but we won't use, so just discard
|
||||||
|
|
||||||
|
curtime = time(NULL);
|
||||||
|
|
||||||
curl_dlnow = dlnow;
|
curl_dlnow = dlnow;
|
||||||
curl_dltotal = dltotal;
|
curl_dltotal = dltotal;
|
||||||
getbytes = curl_dlnow / (time(NULL) - curl_starttime); // To-do: Make this more accurate???
|
|
||||||
|
if (curtime > curl_starttime)
|
||||||
|
{
|
||||||
|
getbytes = curl_dlnow / (curtime - curl_starttime); // To-do: Make this more accurate???
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getbytes = 0;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue