« Yet more junk | Main | Fear of Folding »

December 06, 2004

Compiler Bugs in C#

I've been working with C# a lot recently. Mainly because I've been limited to a Windows development environment, and I figured why not go learn something new. In my travels, I've come across this interesting bug:
double out_val, my_val, clip_val;
//
// do some code here to set my_val and clip_val
//
out_val = (my_val < clip_val) ? clip_val : my_val;

The above statement works perfectly fine for almost all cases of testing, except one. When my_val gets a value that can be seen as NaN or +Infinity, the statement fails in a most peculiar fashion. The if portion of the test correctly executes, meaning it knows which is greater, but despite the proper logic the compiler will always select the else case.

One of my co-workers and I tried to debug this through the disassembly, but decided that our time was better spent working around this bug. Eric seems to think that there might be a way to violate the C# security model with this behavior, but hasn't been able to prove anything on that yet.

Posted by Dan at December 6, 2004 10:05 PM

Comments