Note: This tutorial assumes that you have completed the previous tutorials: Arrays, Stencils.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Buffer Overflow Detection

Description: Detecting ecl array over/under runs.

Keywords: ecl arrays buffer overflow

Tutorial Level: INTERMEDIATE

Arrays also provide a feature to allow for buffer overflow checking - for both fixed and dynamic arrays. Often programs pull pointers to various elements on the contiguous array (especially in really low level routines like vision routines), it is important to know when the stack or heap is being under or over run.

Such functionality can be enabled by declaring the ECL_MEM_CHECK_ARRAYS macro when compiling.

Internally, this entails pre/appending some magic characters to the underlying array and then occasionally performing manual checks to ensure that the magic chars haven't been disturbed.

   1 #define ECL_MEM_CHECK_ARRAYS
   2 
   3 void worker_function( int* i) {
   4     // do some work here, possibly overrunning or underrunning
   5 }
   6 
   7 int main() {
   8     Array<int,4> array; array << 1, 2, 3, 4;
   9     while ( control_loop_running ) {
  10 
  11         int* istart = array[0];
  12         worker_function(i_start);
  13 
  14         if ( array.bufferUnderRun() ) { std::cout << "WARNING! We have an underrun problem houston!" << std::endl; }
  15         if ( array.bufferOverRun() ) { std::cout << "WARNING! We have an overrun problem houston!" << std::endl; }
  16         if ( array.bufferOverFlow() ) { std::cout << "WARNING! We have an unknown problem houston!" << std::endl; }
  17     }

Wiki: ecl_containers/Tutorials/Buffer Overflow Detection (last edited 2012-01-18 14:30:28 by DanielStonier)