Fix small error introduced by earlier retain newline fix.

The last retain newline fix did not check for if p < n before trying to retain the newline.
If this check is not made it will cause the position to go past the null byte on strings
that do not end with a newline character.