TOOLBOX Statement with Wrong Array Can Corrupt Listing or Hang (65938)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a

This article was previously published under Q65938

SUMMARY

You must be careful to pass the correct number of array elements to QuickBASIC's TOOLBOX statement when passing or receiving data.

You can easily cause a system error, hang, or garbage in the QuickBASIC Listing window if you pass incorrect parameters or arrays to the TOOLBOX statement in QuickBASIC for Macintosh. (You must usually restart the Macintosh after a System bomb.)

The garbage in the Listing window will not be written to your program as long as you do not Save after the program was corrupted. If you see garbage in the Listing window, you should exit without saving, restart QuickBASIC, and reload your source file (which will be restored to its condition at the last Save).

TOOLBOX, which is an MBLC routine built into QuickBASIC, is a powerful statement that lets you make many Macintosh ROM traps; however, you must be careful to pass only the correct parameters to TOOLBOX.

This information applies to Microsoft QuickBASIC versions 1.00 and 1.00a for the Apple Macintosh system.

MORE INFORMATION

Problems can occur especially when using an array to represent a record structure or hold rectangle coordinates. If the array is not dimensioned to the proper size, it is possible for initialized arrays or arrays returned from the TOOLBOX call to overwrite the symbol table or other parts of memory.

For example, many ROM trap routines require an array as an argument. When you use an array to hold the coordinates of a rectangle, you must dimension the array to have exactly four elements. If you are using the default OPTION BASE 0, then you must DIM rect%(3), which gives you four elements; rect%(0) through rect%(3). If you are using OPTION BASE 1, you must DIM rect%(4), which gives you four elements; rect%(1) through rect%(4).

If you dimension the array with DIM rect%(4) and fail to use OPTION BASE 1, the actual number of elements that you have will be five elements; rect%(0) through rect%(4). This extra element can overwrite the symbol table, the Listing window, or other parts of memory.

This problem can also occur for any TOOLBOX call that requires information to be returned into a record structure, such as a grafport. If you don't dimension an array large enough to store all the data returned, this extra data can overwrite memory, giving the same problems.

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:KB65938