Skip to content

Commit 1cff9da

Browse files
committed
Fixing serious bug in JMP calculations
1 parent b83d6fe commit 1cff9da

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

workspace/assembler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude = ["*"]
1515
include = ["README.md", "LICENSE", "COPYRIGHT", "src/**/*.rs", "Cargo.toml", "rustfmt.toml", "clippy.toml"]
1616
readme = "README.md"
1717
publish = true
18-
version = "0.9.5"
18+
version = "0.9.6"
1919

2020
[dependencies]
2121
libc = "^0.2"

workspace/assembler/src/ByteEmitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl ByteEmitter
129129

130130
let displacement = (target_instruction_pointer as isize) - end_of_jmp_instruction;
131131

132-
if unlikely!(displacement >= -127 && displacement < 128)
132+
if unlikely!(displacement < -128 && displacement > 127)
133133
{
134134
return Err(())
135135
}

workspace/assembler/src/ShortJmpResult.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/// Represents the result of attempting a mnemonic with a short jump.
66
///
7-
/// Will be an error if a label could be resolved and the jump exceed -127 >= < 128 bytes.
7+
/// Will be an error if a label could be resolved and the jump exceeded the (inclusive range) -128 to +127 bytes.
88
///
99
/// In this case, the instruction stream will be reset to where it was before the prefixes, opcodes and displacements where emitted for the `Jcc` instruction.
1010
pub type ShortJmpResult = Result<(), ()>;

workspace/assembler/src/mnemonic_parameter_types/memory/MemoryOperand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl MemoryOperand
593593
// This logic determines what the value of the mod bits will be.
594594
// It also controls how many immediate bytes we emit later.
595595
let displacement = self.get_displacement();
596-
let mod_ = if displacement < -128 || displacement >= 128
596+
let mod_ = if displacement < -128 || displacement > 127
597597
{
598598
Self::Mod_0b10
599599
}

0 commit comments

Comments
 (0)