C/C++ overwriting array bounds -
what way detect bugs overwrite array bound?
int a[100]; (int = 0; i<1000; i++) a[i] = i;
it helpful collect list of different strategies people have used in experience uncover bugs of type. example, doing backtrace on point of memory fault (for me doesn't work because stack has been corrupted).
- static code analysis (e.g. lint)
- runtime memory analysis (e.g. valgrind)
- avoid fixed-size buffers, prefer dynamically sized containers
- use sizeof() instead of magic numbers whenever can
Comments
Post a Comment