Skip to content

Commit

Permalink
check stack len before getting value
Browse files Browse the repository at this point in the history
  • Loading branch information
pventuzelo committed Nov 22, 2019
1 parent 7bb570a commit 5080040
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/llvm-backend/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,16 @@ impl State {
&self,
n: usize,
) -> Result<&[(BasicValueEnum, ExtraInfo)], BinaryReaderError> {
self.stack
.get(self.stack.len() - n..)
.ok_or(BinaryReaderError {
if self.stack.len() < n {
return Err(BinaryReaderError {
message: "invalid value stack",
offset: -1isize as usize,
})
});
}

let new_len = self.stack.len() - n;
Ok(&self.stack[new_len..])

}

pub fn popn_save_extra(
Expand Down

0 comments on commit 5080040

Please sign in to comment.