Core was generated by `null'.
Program terminated with signal 11, Segmentation fault.
#0 strlen () at /usr/src/lib/libc/arch/amd64/string/strlen.S:124
124 /usr/src/lib/libc/arch/amd64/string/strlen.S: No such file or directory.
in /usr/src/lib/libc/arch/amd64/string/strlen.S
(gdb) bt
#0 strlen () at /usr/src/lib/libc/arch/amd64/string/strlen.S:124
#1 0x00001e30183ddade in puts (s=0x0) at /usr/src/lib/libc/stdio/puts.c:45
#2 0x00001e2d521009f1 in _start () from /home/mulander/code/c/null
#3 0x0000000000000000 in ?? ()
Current language: auto; currently asm
(gdb) Quit
Heh. http://www.tedunangst.com/flak/post/printf-null-in-the-wild
It also happens on OpenBSD.
What happens on OpenBSD?
From gdb on the core file:
That’s because gcc helpfully replaces printf with fputs. Try a format string like “null prints like %s\n”.
Hah! Thanks learned something interesting today :)
Wait, what? wtf?
If I asked for printf, I want printf.
I mean it’s an optimizing compiler, and it knows lots of things that can be optimized.