Friday, October 23, 2009

The Most Stupid Bug of the Year

In the header file yabasic.h, distributed with the Yabasic source, there's a carefully-organised, enumerated list of Yabasic functions. I tidied it up and sorted everything alphabetically into groups of functions with one argument and zero, two, and three arguments:

/* Yabasic functions (sorted carefully by number of arguments). */
enum functions {
fZEROARGS, fRAN2,

fONEARGS, fABS, fACOS, fASC, fASIN, fATAN, fATAN2, fCHR, fCOS,
fEXP, fFRAC, fINT, fLEN, fLOG, fLOWER, fLTRIM, fMAX, fMIN,
fRAN, fRTRIM, fSIG, fSIN, fSQR, fSQRT, fSTR, fSYSTEM, fTAN, fTELL,
fTRIM, fUPPER, fVAL,

fTWOARGS, fAND, fEOR, fINSTR, fLEFT, fLOG2, fMID2, fOR, fRIGHT,
fRINSTR,

fTHREEARGS, fINSTR2, fMID, fRINSTR2
};

See if you can notice the bug before you continue reading. Trust me, it's not difficult to find if you know Yabasic.

It turns out that in the process of sorting the functions into their respective groups, I incorrectly placed fMAX and fMIN (corresponding to the functions max () and min (), respectively) in the group of functions taking only one argument. If you are familiar with Yabasic, you will know that both of these functions actually take two parameters. I was surprised when I ran a program that used one of these functions and was rewarded with a segmentation fault. It only took me a minute or two to figure out where the problem was and fix it, but I reckon it wins the prestigious title of Most Stupid Bug of the Year. And the year isn't even over yet...

Anyway, fMAX and fMIN are now in their proper places, in the group of functions accepting two parameters:

/* Yabasic functions (sorted carefully by number of arguments). */
enum functions {
fZEROARGS, fRAN2,

fONEARGS, fABS, fACOS, fASC, fASIN, fATAN, fATAN2, fCHR, fCOS,
fEXP, fFRAC, fINT, fLEN, fLOG, fLOWER, fLTRIM, fRAN, fRTRIM, fSIG,
fSIN, fSQR, fSQRT, fSTR, fSYSTEM, fTAN, fTELL, fTRIM, fUPPER, fVAL,

fTWOARGS, fAND, fEOR, fINSTR, fLEFT, fLOG2, fMAX, fMID2, fMIN, fOR,
fRIGHT, fRINSTR,

fTHREEARGS, fINSTR2, fMID, fRINSTR2
};

So all is now well.

2 comments:

  1. There's hardly ever been a bug which has *not* made me feel stupid, so... don't fret! ;-)

    ReplyDelete
  2. Aye, 99.999% of bugs are something extremely silly, like

    *** CODE ***
    clear screen
    pritn "Hello World"
    sleep
    *** /CODE ***

    Been there, done that, goin to get there and do it still like n^c times ;)

    ReplyDelete

Note: Only a member of this blog may post a comment.