Make sure we don't run out of the output buffer. Maybe fixes bug #3557