9.14 Use runtime subscript checking


9.14 Use runtime subscript checking

9.14.1 Basic tactic

Use compiler options to generate runtime subscript checking.

9.14.2 Purpose

Determine whether there are any array subscripts that are invalid for the test data you have available.

9.14.3 Questions answered

  • Where are invalid array references coming from?

  • When are invalid array references occurring?

9.14.4 Potential problems

  • If your program makes a lot of array references in tightly nested loops, you could slow down execution significantly.

  • Some compilers don’t offer this option.

9.14.5 Related tactics

  • Put pad variables between arrays so that invalid references that haven’t been found yet don’t effect computation.

  • Reorder array declarations so that invalid references that haven’t been found yet don’t effect computation.

  • Use preprocessor macros to cover array accesses and check subscripts.

9.14.6 Choosing tactics

Use this tactic when one of the following conditions is true:

  • The compiler doesn’t do subscript checking by default.

  • A bug occurs when the program is run standalone, but not when it’s run under a debugger.

  • A bug occurs when the program is run under one user account (and environment), but not when it’s run under another.

Use this tactic at least once before the program is put into production, as an additional testing strategy.

9.14.7 Language specifics

  • C++: Pointer arithmetic can be the equivalent of array indexing, so it’s desirable to check pointer references as well.

  • Java: The Java runtime always checks array references, so the tactic is unnecessary.

  • C: Pointer arithmetic can be the equivalent of array indexing, so it’s desirable to check pointer references as well.

  • Fortran: This tactic isn’t relevant to Fortran pointers.




Debugging by Thinking. A Multidisciplinary Approach
Debugging by Thinking: A Multidisciplinary Approach (HP Technologies)
ISBN: 1555583075
EAN: 2147483647
Year: 2002
Pages: 172

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net