curl-library
Re: curl_easy_setopt() typechecker, try2
Date: Thu, 28 Feb 2008 07:27:02 +0000
Michal Marek wrote:
> > curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, TRUE);
> >
> > (and TRUE is a #define 1, and this is a 32bit arch)
>
> The warning is currently intended and actually correct, although a bit
> pedantic.
If the argument is fetched in curl_easy_setopt using `va_arg(ap,long)',
then the code may be actually buggy on 64-bit architectures.
The caller may pass a 32-bit value on the stack, and the callee parse
a 64-bit value from the stack, so 32 bits of the value seen in the
callee can be garbage. In this case, if you passed FALSE, the callee
might interpret it as TRUE instead. Not what you want, a real bug.
> E.g this is what printf("%ld\n", 1) produces (with recent
> enough gcc and glibc):
>
> $ gcc -m32 -Wall print.c
> print.c: In function ‘main’:
> print.c:5: warning: format ‘%ld’ expects type ‘long int’, but argument 2
> has type ‘int’
> $ file a.out
> a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for
> GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped
Same reason. On a 64-bit architecture, it's calling with 32-bit value
1, but the callee parses 64-bits from the argument stack, reading 32
bits of garbage. It really might print a value different from 1.
-- Jamie
Received on 2008-02-28