Fix output length calculation.