Skip to main content
added 120 characters in body
Source Link
Wim Coenen
  • 67k
  • 14
  • 162
  • 253

Is there a way, at runtime, for me to detect any instances of accessing arrays with negative indexes?

Replace your global array by std::vector. Replace use of the array[index] syntax by

vector.at(index)

This does the same thing except thatexactly what you ask for: it adds runtime array bound checks.

Replace your global array by std::vector. Replace use of the array[index] syntax by

vector.at(index)

This does the same thing except that it adds array bound checks.

Is there a way, at runtime, for me to detect any instances of accessing arrays with negative indexes?

Replace your global array by std::vector. Replace use of the array[index] syntax by

vector.at(index)

This does exactly what you ask for: it adds runtime array bound checks.

Source Link
Wim Coenen
  • 67k
  • 14
  • 162
  • 253

Replace your global array by std::vector. Replace use of the array[index] syntax by

vector.at(index)

This does the same thing except that it adds array bound checks.