Fix an off-by-one error that can cause a segfault during sync.