Fix off by one errors after run by -fsanitize=address