Skip to content

Commit

Permalink
Merge pull request #9 from theseus-rs/fix-instruction-serialization
Browse files Browse the repository at this point in the history
fix: correct tableswitch and lookupswitch serialization
  • Loading branch information
brianheineman authored Jul 23, 2024
2 parents ef1d05c + 11deba6 commit 3c3e735
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Upload to codecov.io
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: lcov.info
fail_ci_if_error: true
Expand Down
87 changes: 38 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ flate2 = "1.0.30"
indoc = "2.0.5"
reqwest = "0.12.5"
tar = "0.4.41"
thiserror = "1.0.61"
tokio = "1.38.0"
zip = "2.1.3"
thiserror = "1.0.63"
tokio = "1.39.1"
zip = "2.1.5"

[workspace.metadata.release]
shared-version = true
Expand Down
8 changes: 4 additions & 4 deletions ristretto_classfile/src/attributes/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ impl Instruction {
high,
offsets,
} => {
let current_position = i32::try_from(bytes.position())?;
let position = u32::try_from(current_position + 1)?;
let position = i32::try_from(bytes.position())?;
let padding = (4 - (position % 4)) % 4;
for _ in 0..padding {
bytes.write_u8(0)?;
Expand All @@ -834,8 +833,7 @@ impl Instruction {
}
}
Instruction::Lookupswitch { pairs, default } => {
let current_position = i32::try_from(bytes.position())?;
let position = u32::try_from(current_position + 1)?;
let position = i32::try_from(bytes.position())?;
let padding = (4 - (position % 4)) % 4;
for _ in 0..padding {
bytes.write_u8(0)?;
Expand Down Expand Up @@ -1229,6 +1227,8 @@ mod test {
let mut bytes = Vec::new();
buffer.set_position(0);
buffer.read_to_end(&mut bytes)?;
assert_eq!(expected_bytes, bytes);

let mut bytes = Cursor::new(expected_bytes.to_vec());
assert_eq!(*instruction, Instruction::from_bytes(&mut bytes)?);
Ok(())
Expand Down

0 comments on commit 3c3e735

Please sign in to comment.