cURL / Mailing Lists / curl-library / Single Mail


Re: Not passing "long" to varargs (was Re: curl_easy_setopt and typeof)

From: David Shaw <>
Date: Sun, 13 Apr 2008 22:24:47 -0400

On Apr 13, 2008, at 12:04 PM, Jamie Lokier wrote:
> The second line of output isn't guaranteed to be the same with every
> compiler: it has undefined behaviour, because an int argument is
> passed to a varargs function expecting long. It could even crash on
> some systems.

Following that logic, wouldn't that mean that this:

   curl_easy_setopt( curl, CURLOPT_MAXREDIRS, -1 );

is incorrect?

After all, as you say, curl_easy_setopt is documented to take a long,
but without a cast, that bare -1 is going to go over as an int.

#include <stdio.h>

main(int argc,char *argv[])
   printf("int is %d bytes and long is %d bytes

   printf(" -1 == %ld\n",-1);
   printf("(long)-1 == %ld\n",(long)-1);

$ gcc bar.c -m64
$ ./a.out
int is 4 bytes and long is 8 bytes
       -1 == 4294967295
(long)-1 == -1

There is probably a heck of a lot of code using libcurl that doesn't
cast constants to long...

Received on 2008-04-14