Skip to content

Commit f7c291b

Browse files
authored
arm: Fix .word reading 4 bytes when less than 4 remain (#285)
1 parent 03a578c commit f7c291b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

objdiff-core/src/arch/arm.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,14 @@ impl Arch for ArchArm {
224224
}
225225

226226
// Check how many bytes we can/should read
227-
let num_code_bytes = if mode == unarm::ParseMode::Data {
228-
// 32-bit .word value should be aligned on a 4-byte boundary, otherwise use .hword
229-
if address & 3 == 0 { 4 } else { 2 }
230-
} else if data.len() >= 4 {
231-
// Read 4 bytes even for Thumb, as the parser will determine if it's a 2 or 4 byte instruction
232-
4
227+
let num_code_bytes = if data.len() >= 4 {
228+
if mode == unarm::ParseMode::Data && address & 3 != 0 {
229+
// 32-bit .word value should be aligned on a 4-byte boundary, otherwise use .hword
230+
2
231+
} else {
232+
// Read 4 bytes even for Thumb, as the parser will determine if it's a 2 or 4 byte instruction
233+
4
234+
}
233235
} else if mode != unarm::ParseMode::Arm {
234236
2
235237
} else {

0 commit comments

Comments
 (0)