[Coco] A bug in Basic09/RunB

Wayne Campbell asa.rand at yahoo.com
Sun Dec 6 20:49:58 EST 2009


When I first learned Basic09, I did not possess the knoweledge and experience that I now have. There were many things that were overlooked in DCom, simply because I did not understand the function. Now, I know more about the function.

I believe I have found a bug in Basic09. With all of the modifications that were made to Basic09 between 2002 and 2006, I cannot be certain that this bug did not exist prior to the modifications. However, if experience is any guide, it may well have gotten broken during the modification process and was never discovered.

The bug is in the way parameters are passed to called procedures. First, any simple variable type (other than boolean) can be passed by value using +0 on the byte, int and real variables, and +"" on strings. To pass a boolean value, use TRUE or FALSE.

Second, as long as the receiving variable is of the correct size, it doesn't matter what type or order you specify the parameter list in. It just has to match the size.

The first bug occurs when you pass a byte by value:

a:BYTE
a:=1
RUN myProc(a+0)
END

PROCEDURE myProc
PARAM a:BYTE

PRINT a

END

The result should be

1

Instead,, it is

0

The wrong byte is being retrieved. All BYTE variables are expanded into INTEGERs before being processed. In this case, the first byte of the integer is being read, not the second. I can never remember which order they are in, so I'm not certain which one is LSB and which one is MSB. To be clear:

  +---+---+
  | 1 | 2 |
  +---+---+

Byte 1 is being read, when byte 2 should be being read.

The second bug occurs when you pass multiple variables into a single variable. Based on the fact that it works correctly, under the following conditions, on the first 2 elements of the receiving array, it should be working correctly for all of the parameters needed to equal its size. The test procedure passed 3 INTEGER variables into 1 3-element INTEGER array.

PROCEDURE testParams
DIM a,b,c:INTEGER
a:=1 \b:=2 \c:=3
RUN recPars(a,b,c)
END

PROCEDURE recPars
DIM cntr:INTEGER
PARAM d(3):INTEGER

FOR cntr:=1 TO 3
PRINT d(cntr)
NEXT cntr
END

Results:

1
2
56 (Parameter Error)

In addition, I added a fourth parameter, a second reference to a, and a 4th element to d. The error occurred in the same position in the array as before. Therefore, the accumulator that is supposed to count the parameter sizes is exiting before the final parameters are being processed.

I do not know enough about assembly language to track down these bugs. Maybe someday, not not any time soon. If someone on this list wants to see if they can figure it out, the source to the modified Basic09 and RunB are on sourceforge.

http://nitros9.cvs.sourceforge.net/viewvc/nitros9/nitros9/3rdparty/packages/basic09/?sortdir=down

I'll report anything else I find out as I go.

Wayne


      



More information about the Coco mailing list