Resizing the text buffer won’t work.
Remove memory corruption error (calculate indices correctly).