Fix an off-by-one; fixes the second bug in trac #3001