Debugging array bounds

J

Joshua Hale

Any suggestions for a debugging tool to help find out of bounds
writes/reads to arrays in a C++ program on a Linux platform? I tried
valgrind, and it found some accesses of uninitialized values, but can't
pick out out-of-bounds writes to stack arrays...

Thanks,

Josh.
 
T

Thomas Matthews

Joshua said:
Any suggestions for a debugging tool to help find out of bounds
writes/reads to arrays in a C++ program on a Linux platform? I tried
valgrind, and it found some accesses of uninitialized values, but can't
pick out out-of-bounds writes to stack arrays...

Thanks,

Josh.

Hmmm, difficult:
void my_function(char * pointer)
{
for (unsigned int i = 0; i < 100; ++i)
{
pointer = 'b';
}
return;
}

int main(void)
{
char small_array[6];
char large_array[512];

my_function(large_array);
my_function(small_array);

return 0;
}

In the function my_function above, how is the tool
to know when the array has gone past its bounds?
The function has no clue as to the length of the
memory region passed to it.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,477
Latest member
ColumbusMa

Latest Threads

Top