development gotcha: incorrect data types

The other day I ran into a code bug that took a while to figure out.  It was so unique (to me) that I thought I’d write about it.

[stextbox id=’info’]Ad: Wonder Chews[/stextbox]

The following pseudo code contains the bug.  The symptom was that mid-execution, the value of position was getting corrupted and thus causing a GPF 1 at the sprintf.

Did you spot the bug?!

I had mistakenly declared timerInterval as an int, rather than a double.  And because I’m not in the habit of error-checking the CVI standard library, the call to GetAsyncTimerAttribute blindly overfilled timerInterval with its double value, which then overwrote the value of position.

[stextbox id=’info’]Ad: scheduling software[/stextbox]

position was the collateral damage because it’s declared before timerInterval.

Now curiously, when I tried to reproduce this bug on another machine, position retained its 0 initialized value.  So you can see how insidious this kind of bug can be — you might not even see it on all machines or at every runtime call.

Footnotes

  1. General Protection Fault

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social Media Auto Publish Powered By : XYZScripts.com