Skip to content

Commit ba1f127

Browse files
committed
pe.data_directories: fix offset computation
1 parent 91f6501 commit ba1f127

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/pe/data_directories.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,13 @@ impl ctx::TryIntoCtx<scroll::Endian> for DataDirectories {
7878
fn try_into_ctx(self, bytes: &mut [u8], ctx: scroll::Endian) -> Result<usize, Self::Error> {
7979
let offset = &mut 0;
8080
for opt_dd in self.data_directories {
81-
if let Some((dd_offset, dd)) = opt_dd {
82-
bytes.pwrite_with(dd, dd_offset, ctx)?;
83-
*offset += dd_offset;
81+
if let Some((_, dd)) = opt_dd {
82+
bytes.gwrite_with(dd, offset, ctx)?;
8483
} else {
85-
bytes.gwrite(&[0; SIZEOF_DATA_DIRECTORY][..], offset)?;
84+
bytes.gwrite([0; SIZEOF_DATA_DIRECTORY].as_slice(), offset)?;
8685
}
8786
}
88-
Ok(NUM_DATA_DIRECTORIES * SIZEOF_DATA_DIRECTORY)
87+
Ok(*offset)
8988
}
9089
}
9190

0 commit comments

Comments
 (0)