Harden tdb_check_used_record against overflow