10/10/2007

Bug of the week

Today I was called to take a look at a problem: A bug that was created by me. Given the context I couldn't figure out why this is happening. Looking at my computer screen, scratching my head, I couldn't figure out why the problem. The line that has the problem looks like this:

SHGNO flag = static_cast(SHGDN_FORPARSING (check()) ? SHGDN_INFOLDER : 0);

The design was, if useRelative() returns true, we apply the SHGDN_INFOLDER flag, otherwise we just use SHGDN_FORPARSING alone. However, with this code, the 'flag' was always set to SHGDN_INFOLDER and made some dev manager send me a furious in Tuesday morning.

So eventually my boss figured out the problem, and the answer is as simple as one damn word: order. Turns out that the bit-wise or operator has higher priority. That is, I assumed that after the code was compiled, the order will be:

SHGDN_FORPARSING (check()) ? SHGDN_INFOLDER : 0));

turns out, it was actually:

(SHGDN_FORPARSING (check())) ? SHGDN_INFOLDER : 0);

Huh, what a shame, a simple bug cuased a high profile break...

沒有留言: