Fix off-by-one in ASSERT and make it more comprehensive.