Thread overview
printf bug ??!
Mar 16, 2006
lanael
Mar 16, 2006
Thomas Kuehne
Mar 17, 2006
lanael
March 16, 2006
void main() {
ulong u =0b100000000000000000000000000000000000000000000000; // 1 and 47 zeros
ulong u1=0b1000000000000000000000000000000000000000000000000; // 1 and 48 zeros
printf("u  = \t %llx \t %llb\n",u,u);
printf("u1 = \t %llx \t %llb\n",u1,u1);
}

output :
u  =     800000000000    100000000000000000000000000000000000000000000000
u1 =     1000000000000    000000000000000000000000000000000000000000000000

it looks like a buffer overflow...


March 16, 2006
lanael schrieb am 2006-03-16:
> void main() {
> ulong u =0b100000000000000000000000000000000000000000000000; // 1 and
> 47 zeros
> ulong u1=0b1000000000000000000000000000000000000000000000000; // 1 and
> 48 zeros
> printf("u  = \t %llx \t %llb\n",u,u);
> printf("u1 = \t %llx \t %llb\n",u1,u1);
> }
>
> output :
> u  =     800000000000
> 100000000000000000000000000000000000000000000000
> u1 =     1000000000000
> 000000000000000000000000000000000000000000000000
>
> it looks like a buffer overflow...

The %llb notation isn't part of the standard printf implementation.
(see C99, ISO 9899 7.19.6.1.8)

I'm not saying that this is a bug or not, but the code isn't portable:
> #include <stdio.h>
>
> int main(){
>	unsigned long long i = 9;
>	printf("%llb\n", i);
>	return 0;
> }

prints "%b" under Linux

Thomas


March 17, 2006
"lanael" <no@mail.never> wrote in message news:mn.84927d63e30b23b4.35838@mail.never...
> printf("u  = \t %llx \t %llb\n",u,u);
> printf("u1 = \t %llx \t %llb\n",u1,u1);

Don't.
Use.
printf.

writefln("u  = \t %x \t %b", u, u);
writefln("u1 = \t %x \t %b", u1, u1);


March 17, 2006
In article <dvd11t$2a4h$1@digitaldaemon.com>, Jarrett Billingsley says...
>

>Don't.
>Use.
>printf.
>

Ok! ok! ok! : I'll add this to my mantra list ! ;)

Anyway, I was thinking that writef() was a just a "bridge" to printf, but I now
see that I was totally wrong. writefx() looks like a complete rewrite of printf
type functions in pure D...


March 18, 2006
"lanael" <lanael_member@pathlink.com> wrote in message news:dvdssk$jed$1@digitaldaemon.com...
> Ok! ok! ok! : I'll add this to my mantra list ! ;)

Hehe :)

> Anyway, I was thinking that writef() was a just a "bridge" to printf, but
> I now
> see that I was totally wrong. writefx() looks like a complete rewrite of
> printf
> type functions in pure D...

Absolutely.  printf is a C function, and as such, has no concept of type safety.  The std.format based functions (like the writef family) are written in D, and use D's variable argument system, making them much more type-safe as well as being D-aware.