fix out-of-bounds access in string display functions. close #1675.

Fix for #1675.

It doesn't handle \t or \r, but at least it doesn't crash.