curl_easy_setopt is declared as: CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
When you pass arguments to ..., the following rules apply: nullptr is converted to void * (C++ only) float is converted to double integer and enum types are promoted (like happens with the unary + operator) int doesn't promote to long just from passing to a ... parameter. Because curl_easy_setopt itself uses the va_arg macro with long, this is undefined behavior. In particular, if long is bigger than int, bad things happen - often a 0 would be interpreted as nonzero due to uninitialized stack memory. -----Original Message----- From: curl-library <[email protected]> On Behalf Of WebMC via curl-library Sent: Tuesday, December 17, 2019 1:27 AM To: Jeff Mears via curl-library <[email protected]> Cc: WebMC <[email protected]> Subject: Re: curl_easy_setopt type checking for C++ Le 09/12/2019 à 22:37, Jeff Mears via curl-library a écrit : > As an example, the following: > curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1); In C, this is broken. > 1 is an "int", but the parameter is defined as "long". what about "implicit cast" ? the argument is passed as "(long)1", right? you can have problem with the reverse cast, because the final type may be unable to describe the first value, or with pointers ChD ------------------------------------------------------------------- Unsubscribe: https://urldefense.com/v3/__https://cool.haxx.se/list/listinfo/curl-library__;!!Ci6f514n9QsL8ck!wtlOk9sgxs-pKmEE2Zp3wH4CWVQ9IIpMrCA0HNgNvcm8tLawMPxI1JvOcM-W27D7$ Etiquette: https://urldefense.com/v3/__https://curl.haxx.se/mail/etiquette.html__;!!Ci6f514n9QsL8ck!wtlOk9sgxs-pKmEE2Zp3wH4CWVQ9IIpMrCA0HNgNvcm8tLawMPxI1JvOcERwNnj8$ ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.html
