Added means of preventing buffer overflow

A method to check if cursor is at the end of the buffer has been
added and ensures the input stops at the end of the buffer.