-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue 1057 + improve llvm/state.rs code #1058
Fix issue 1057 + improve llvm/state.rs code #1058
Conversation
… everywhere needed in state.rs
let index = self | ||
.control_stack | ||
.len() | ||
.checked_sub(1 + (depth as usize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too.
let index = self | ||
.control_stack | ||
.len() | ||
.checked_sub(1 + (depth as usize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.checked_sub(1)
.checked_sub(depth as usize)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not possible because checked_sub
return an Option
.
Do you prefer this way?
let tmp_index = self
.control_stack
.len()
.checked_sub(1).ok_or(BinaryReaderError {
message: "frame_at_depth: invalid control stack depth",
offset: -1isize as usize,
})?;
let index = tmp_index.checked_sub(depth as usize)
.ok_or(BinaryReaderError {
message: "frame_at_depth: invalid control stack depth",
offset: -1isize as usize,
})?;
Ok(&self.control_stack[index])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! No, I prefer the code as it is, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to use .and_then
here. I noticed the potential for overflow there too, but I figured it's very unlikely. I think it should be fine as-is!
For future readers who may end up here who didn't understand what I meant:
self
.control_stack
.len()
.checked_sub(1)
.and_then(|n| n.checked_sub(depth as usize))
.ok_or(BinaryReaderError {
message: "frame_at_depth: invalid control stack depth",
offset: -1isize as usize,
})?;
and_then
acts like Monadic bind (>>=
) in Haskell.
let index = self | ||
.control_stack | ||
.len() | ||
.checked_sub(1 + (depth as usize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! No, I prefer the code as it is, thanks.
bors r+ |
Merge conflict |
bors r+ |
1058: Fix issue 1057 + improve llvm/state.rs code r=syrusakbary a=pventuzelo # Description This pull request is doing: - Fix issue #1057 (subtraction overflow panic in State::peek1_extra) by using `checked_sub` - replace other part of `state.rs` subject to potential substration overflow with `checked_sub` - add more detail on the Errors messages in `state.rs` - rename some variable for better understanding of the code. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Patrick Ventuzelo <[email protected]> Co-authored-by: Syrus Akbary <[email protected]>
Build succeeded |
Description
This pull request is doing:
checked_sub
state.rs
subject to potential substration overflow withchecked_sub
state.rs
Review