Fix off-by-one error when computing padding