NO CARRIER

Computers, Science, Technology, Xen Virtualization, Hosting, Photography, The Internet, Geekdom And More

GCC has a little big bug

Posted on | November 21, 2007 | No Comments

There’s been a flurry of concerns over some very odd behavior found in gcc, the GNU collection of compilers. Since GCC compiles much more than just C, I don’t call it the GNU C compiler any more, as that would be a bit of a misnomer.

GCC has a built in abs() (absolute value) function that has a little bug, under some conditions gcc might believe that -x = x. You can compile the following code to see the odd behavior in action:

include <stdio.h>

int main(void) { int i=2; if( -10abs (i-1) == 10abs(i-1) ) printf ("Wow, -10 == 10!\n"); else printf ("Your compiler is older than dirt!\n"); return 0; }

Of course, substitute 10 for any value. Off goes a flurry of people wondering if every program on their computer is now insecure. No, this bug does not render your encryption useless, it does not open your computer up to attacks and it won’t kill your goldfish after becoming self aware.

If you are using gcc version 3+, you should update your OS. GNU has issued a bugfix for the problem, chances are that your OS packager has already applied the small patch and an update is available.

Doing a quick grep through /usr/src on my machine, I could not find anything that used the abs() (including the kernel), most programs have their own function or macro for this functionality. This means, likely, that this bug has been well known but not reported for years, typical.

If you (like me) prefer gcc 3.4, you might want to grab the patch and apply it to your gcc source and rebuild. Its likely that OS packagers are only going to update whatever version that their meta ‘gcc’ package delivers. The patch is really trivial, as is the bug itself.

Why is it when the kernel has 12 regressions in a week, nobody complains, yet when gcc has one little bug the world imagines that the sky is falling? I never did understand that phenomenon.

Comments

Leave a Reply





  • Monkey Plus Typewriter
  • Stack Overflow

  • Me According To Ohloh

  • Meta