POSIX.1 states that dbm_nextkey must return an invalid key
(i.e., key.dptr == NULL) after the end of the database was reached.
The current implementation of hash_seq will incorrectly restart
the key sequence after the end of the database is reached.
Fix this by checking the "current bucket" index when R_NEXT is passed.
Sponsored by: Klara, Inc.