digitalmars.D.bugs - printf bug ??!
- lanael (14/14) Mar 16 2006 void main() {
- Thomas Kuehne (13/33) Mar 16 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Jarrett Billingsley (7/9) Mar 16 2006 Don't.
- lanael (5/8) Mar 17 2006 Ok! ok! ok! : I'll add this to my mantra list ! ;)
- Jarrett Billingsley (7/13) Mar 17 2006 Hehe :)
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...
Mar 16 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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 -----BEGIN PGP SIGNATURE----- iD8DBQFEGcuj3w+/yD4P9tIRAqu7AKCpEp/rD8aVQO8quVn6KH5rp7zxvACdGelJ SWSf/QenPQsqubs6ftznCOg= =70Te -----END PGP SIGNATURE-----
Mar 16 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);
Mar 16 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...
Mar 17 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.
Mar 17 2006