Fix off-by-one with sanity check.