Check the boundaries
Check the boundaries,
and of course,
Check the boundaries.
And if you forgot one of these rules, use Valgrind. This applies to arrays, strings, and pointers, but it's really very easy to forget about what you're really doing when doing allocations and memory aritmethics.