fix crash when the number of output lines is small

This fixes a bug when the number of output lines is less than the
requested output size