Fix #263: potential UnboundLocalError: 'length'