We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bbcdb0a commit 24dccb0Copy full SHA for 24dccb0
crates/leanVm/src/memory/address.rs
@@ -15,10 +15,15 @@ impl Add<usize> for MemoryAddress {
15
type Output = Result<Self, MathError>;
16
17
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.
21
self.offset
22
.checked_add(other)
23
.map(|offset| Self {
24
+ // Keep the same segment index.
25
segment_index: self.segment_index,
26
+ // Use the new (safe) offset.
27
offset,
28
})
29
.ok_or_else(|| MathError::MemoryAddressAddUsizeOffsetExceeded(Box::new((self, other))))
0 commit comments