curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi_perform sometimes does not return while ...

From: myLC--- via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 8 Jan 2019 14:54:26 +0100

> Thanks to the suggestion I received, I finally fixed the problem.
>
> timediff_t Curl_timediff(struct curltime newer, struct curltime older)
> {
> - timediff_t diff = newer.tv_sec-older.tv_sec;
> + timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec
>
> This code apsolutely worked well, no endless loop any more.
>
> The cast has higher precedence than the addition, so this would end up
> signed subtracting unsigned resulting unsigned, I think.
> Is my understanding wrong?

I'm afraid it's wrong. Your modified version is correct, though missing
the semicolon (;).

Your first version does this:

timediff_t diff = ( (timediff_t)newer.tv_sec ) - older.tv_sec;

See operator precedence here:

https://en.cppreference.com/w/c/language/operator_precedence

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-01-08