Trailing blanks and buffer overflows

Coverity scan check caught several places where possible buffer overflows
may happen. Also cleaned-up and removed a bunch of trailing spaces.
Merge pull request #726 from JoesCat/master

Trailing blanks and buffer overflows