Skip to content

Commit 24dccb0

Browse files
committed
better doc
1 parent bbcdb0a commit 24dccb0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

crates/leanVm/src/memory/address.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ impl Add<usize> for MemoryAddress {
1515
type Output = Result<Self, MathError>;
1616

1717
fn add(self, other: usize) -> Result<Self, MathError> {
18+
// Try to compute the new offset by adding `other` to the current offset.
19+
//
20+
// This uses `checked_add` to safely detect any potential `usize` overflow.
1821
self.offset
1922
.checked_add(other)
2023
.map(|offset| Self {
24+
// Keep the same segment index.
2125
segment_index: self.segment_index,
26+
// Use the new (safe) offset.
2227
offset,
2328
})
2429
.ok_or_else(|| MathError::MemoryAddressAddUsizeOffsetExceeded(Box::new((self, other))))

0 commit comments

Comments
 (0)