问题
I would like to analyse my C++ code to find bad access in vectors and arrays (out of range access), is there a tool for that ?
thanks in advance
回答1:
You can compile with _GLIBCXX_DEBUG and _GLIBXX_DEBUG_PEDANTIC defined if your are using gcc. This will enable glibc assertions to be raised if out of bounds access is requested.
Testing with valgrind::memcheck will also reveal bad memory reads
回答2:
Yes: Valgrind.
And many others: http://en.wikipedia.org/wiki/Memory_debugger.
Note also that most implementations of e.g. std::vector have a debug mode where they will do run-time bounds checking.
回答3:
There are some paid tools, which does static analysis:
klockwork
coverity
IBM Rational Purify does dynamic analysis.
回答4:
create a class on you arrays and create some controlling functions in that class with operators and .... then use this class .
来源:https://stackoverflow.com/questions/7497637/c-detect-out-of-range-access