@@ -492,13 +492,19 @@ impl<'a> Iterator for MemoryChunkIterator<'a> {
492492
493493 let account_index = self . account_index . get_or_insert_default ( ) ;
494494
495+ // Do not allow iteration over account/non-account boundary.
496+
497+ // First check whether the region is an account or not
495498 loop {
496499 if let Some ( account) = self . accounts . get ( * account_index) {
500+ // region is either account data or 10k resize region
497501 let account_addr = account. vm_data_addr ;
498502 let resize_addr = account_addr. saturating_add ( account. original_data_len as u64 ) ;
499503
500504 if resize_addr < region. vm_addr {
501- // region is after this account, move on next one
505+ // region is not this account, move onto the next account
506+
507+ // note that we iterate in the same linear direction as regions
502508 * account_index = account_index. saturating_add ( 1 ) ;
503509 } else {
504510 region_is_account =
@@ -558,17 +564,24 @@ impl DoubleEndedIterator for MemoryChunkIterator<'_> {
558564 . account_index
559565 . get_or_insert_with ( || self . accounts . len ( ) . saturating_sub ( 1 ) ) ;
560566
567+ // Do not allow iteration over account/non-account boundary.
568+
569+ // First check whether the region is an account or not
561570 loop {
562571 let Some ( account) = self . accounts . get ( * account_index) else {
563572 // address is after all the accounts
564573 region_is_account = false ;
565574 break ;
566575 } ;
567576
577+ // region is either account data or 10k resize region
568578 let account_addr = account. vm_data_addr ;
569579 let resize_addr = account_addr. saturating_add ( account. original_data_len as u64 ) ;
570580
571581 if * account_index > 0 && account_addr > region. vm_addr {
582+ // region is not this account, move onto the previous account
583+
584+ // note that we iterate in the same linear direction as regions
572585 * account_index = account_index. saturating_sub ( 1 ) ;
573586 } else {
574587 region_is_account = region. vm_addr == account_addr || region. vm_addr == resize_addr;
0 commit comments