Fix problem converting characters between 2 streams

Out of buffer in output could lead to premature conversion.
Also fix test to detect this with or without --enable-extra-checks option.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Merge branch 'master' into travis2