Re: libc/printf bug
- From: Måns Rullgård <mru@xxxxxxxxxxxxx>
- Date: Mon, 27 Feb 2006 21:34:38 +0000
"bill pursell" <bill.pursell@xxxxxxxxx> writes:
The following code exhibits unexpected behavior. Either it's
a bug in libc, or the author (me) is blind as a bat. Am I missing
something here, or is something horribly wrong? It appears
that printf is mangling the address unless the second argument
gets cast. I don't see that the cast should have any effect at all
on the output. Any thoughts?
[tmp]$ cat printf_bug.c
int
main()
{
float a=0;
printf("%p\n", &a);
printf("%x %p\n", a, &a);
printf("%x %p\n", (int)a, &a);
}
[tmp]$ ./a.out
0xfefb6764
0 (nil)
0 0xfefb6764
[tmp]$
When passed to a function with variable arguments, float arguments are
promoted to double. A double is usually 64 bits, and the %x format
uses only 32 of these, leaving the remaining 32 for the %p.
--
Måns Rullgård
mru@xxxxxxxxxxxxx
.
- References:
- libc/printf bug
- From: bill pursell
- libc/printf bug
- Prev by Date: Re: libc/printf bug
- Next by Date: Re: libc/printf bug
- Previous by thread: Re: libc/printf bug
- Next by thread: Re: libc/printf bug
- Index(es):
Relevant Pages
|