dfa: fix buffer overflow checks to avoid integer overflows.