Skip to content

Commit

Permalink
fix: modifier depth between 1<<30 and u32::MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Sep 17, 2024
1 parent 48456d6 commit 6cea41b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/artifacts/solc/src/sourcemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ impl SourceElement {
}

#[inline]
fn set_modifier_depth(&mut self, modifier_depth: u32) {
self.set_jump_and_modifier_depth(self.jump(), modifier_depth);
fn set_modifier_depth(&mut self, modifier_depth: usize) -> Result<(), SyntaxError> {
if modifier_depth > (1 << 30) - 1 {
return Err(SyntaxError::new(None, "modifier depth overflow"));
}
self.set_jump_and_modifier_depth(self.jump(), modifier_depth as u32);
Ok(())
}

#[inline]
Expand Down Expand Up @@ -369,7 +373,7 @@ impl SourceElementBuilder {
get_field!(|jump| element.set_jump(jump));
// Modifier depth is optional.
if let Some(modifier_depth) = self.modifier_depth {
element.set_modifier_depth(modifier_depth.try_into()?);
element.set_modifier_depth(modifier_depth)?;
}
Ok(element)
}
Expand Down

0 comments on commit 6cea41b

Please sign in to comment.