|
|
Awesome GCC Literal Suffix Bug
The setup: $ cat bug.c
#include <stdio.h>
static float f(float x) {
printf("f() called\n");
return x + 1;
}
int main (int argc, const char *argv[]) {
#if TYPO
float y = f(42f);
#else
float y = f(42.f);
#endif
printf("y: %f\n", y);
return 0;
}
Let’s build+run it normally: $ gcc -o bug bug.c && ./bug f() called y: 43.000000 OK, let’s insert the typo: $ gcc -DTYPO=1 -o bug bug.c && ./bug bug.c:10:14: error: invalid suffix "f" on integer constant OK, still in the land of the sane. Now let’s add a couple of flags Xcode 2.4 normally adds for a Debug target, $ gcc -arch i386 -fasm-blocks -DTYPO=1 -o bug bug.c && ./bug y: -1.999849 Lovely bug, isn’t it? When targeting Intel and CodeWarrior-style assembly blocks are enabled, It gets better. The entire statement hosting the errant literal just disappears. It’s as if you never even called it. Notice Turns out not all literal suffixes have expose the bug, only the following ones: Tuesday, September 11, 2007
|
Contact Me Topics RSS Feed Linkblog
Bill Bumgarner Brent Simmons Daniel Jalkut Dave Dribin Eric Albert Eric Rescorla Eric Sink Greg Miller Gus Mueller Jeremy Zawodny John Gruber Mark Dalrymple Michael Tsai Peter Ammon Raymond Chen Ryan Wilcox Scott Stevenson Steven Frank The Daily WTF we hates software Wil Shipley |
Copyright © 1997-2008 Jonathan 'Wolf' Rentzsch. All rights reserved.
Questions? Comments? Contact Me.