It's probably simply that you've got garbage characters at the end of buff - there is no good way of predicting what they will do or what effect they will have, since it's "random" characters - and they may well mean just about anything including "move down a row" or "move up a row" or anything else that you can't tell what it means.

[Note, they are not as random as the result of rand(), but they are random in the sense that they are not defined by the program as such - they will have whatever value happens to be in the memory at that location - which if you have the same calling sequence for multiple runs will possibly be similar or even the same].

--
Mats