Buffer Overflow Causes. ©2002, Jedidiah R. Crandall, Susan L. Gerhart, Jan G. Hogle.  http://sfsecurity.pr.erau.edu
Formatting and logical errors – Problem.
The size in bytes of the input might not be what causes the buffer overflow, it might be the input itself. 
For example, if you’re converting a large integer to a string (maybe in ternary) make sure the buffer is long enough to hold all possible outputs.