Skip to content

Commit

Permalink
Convert the starts-at-1 file register into an array index before usin…
Browse files Browse the repository at this point in the history
…g it to index an array.
  • Loading branch information
khuey committed Aug 16, 2016
1 parent fca924d commit 20e8bcd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,10 @@ impl<'input, 'header, Endian> LineNumberRow<'input, 'header, Endian>
/// The source file corresponding to the current machine instruction.
pub fn file(&self) -> Option<Ref<FileEntry<'input>>> {
let file_names = self.header.file_names.borrow();
let file_idx = self.registers.file as usize;
// NB: registers.file starts counting at 1.
let file_idx = self.registers.file as usize - 1;
if file_names.len() > file_idx {
Some(Ref::map(file_names, |names| &names[self.registers.file as usize]))
Some(Ref::map(file_names, |names| &names[file_idx]))
} else {
None
}
Expand Down

0 comments on commit 20e8bcd

Please sign in to comment.