Buffer Overflow Causes. ©2002, Jedidiah R. Crandall, Susan L. Gerhart, Jan G. Hogle.  http://sfsecurity.pr.erau.edu
Off-by-one errors - Problem.
Off-by-one errors occur when a programmer takes the proper precautions in terms of bounds checking, but maybe puts a 512 where she should have put a 511.
Can happen to the best programmers no matter how well-informed they are about buffer overflows.