This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

runtime error checking for array out of bound

Hi,

i'm using the following platform:

- tirtos_tivac_2.10.01.38

- CCS  6.0.1.00040

- xdctools_3_30_06_67_core

And i have an array with 100 element, and by mistake i had an access to this array using a for loop that count up to 255 element, so i have an array index out of bound.

my question is, how can i let my code generate an exception in this case?

Thanks,

Mohamed Fawzy

  • An easy way is to add an assert or Assert_isTrue(). Both of them can enabled and disabled to avoid the runtime performance hit.
  • Actually, i think your suggestion is good if i was passing the length to a function so i can validate the received parameter but the out of bound appeared in a for loop, and if the developer was concentrating little bit, he should be able to put the correct array length.
    So, as long as there is no run time support for such errors, so the static analysis will be my back up plan.

    Thanks,
    Mohamed Fawzy