length = remaining if length > remaining