Skip to content

Commit

Permalink
Fix build with some feature combinations (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc authored Jan 6, 2024
1 parent e719bd6 commit 69d3879
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- run: cargo build --no-default-features --features read
- run: cargo build --no-default-features --features write
- run: cargo build --no-default-features --features read_core,write_core,coff
- run: cargo build --no-default-features --features read_core,write_core,elf
- run: cargo build --no-default-features --features read_core,write_core,macho
- run: cargo build --no-default-features --features read_core,pe
- run: cargo build --no-default-features --features read_core,wasm
- run: cargo build --no-default-features --features read_core,xcoff,unstable
- run: cargo build --no-default-features --features doc
- run: cargo test --no-default-features --features read
- run: cargo test --no-default-features --features write
- run: cargo test --no-default-features --features read_core,write_core,coff
- run: cargo test --no-default-features --features read_core,write_core,elf
- run: cargo test --no-default-features --features read_core,write_core,macho
- run: cargo test --no-default-features --features read_core,write_core,pe
- run: cargo test --no-default-features --features read_core,wasm
- run: cargo test --no-default-features --features read_core,xcoff
- run: cargo test --no-default-features --features std
- run: cargo test --no-default-features --features compression
- run: cargo test --no-default-features --features unaligned
- run: cargo test --no-default-features --features doc

cross:
strategy:
Expand Down
10 changes: 7 additions & 3 deletions src/read/macho/load_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,15 @@ mod tests {

#[test]
fn cmd_size_invalid() {
let mut commands = LoadCommandIterator::new(LittleEndian, &[0; 8], 10);
#[repr(align(16))]
struct Align<const N: usize>([u8; N]);
let mut commands = LoadCommandIterator::new(LittleEndian, &Align([0; 8]).0, 10);
assert!(commands.next().is_err());
let mut commands = LoadCommandIterator::new(LittleEndian, &[0, 0, 0, 0, 7, 0, 0, 0, 0], 10);
let mut commands =
LoadCommandIterator::new(LittleEndian, &Align([0, 0, 0, 0, 7, 0, 0, 0, 0]).0, 10);
assert!(commands.next().is_err());
let mut commands = LoadCommandIterator::new(LittleEndian, &[0, 0, 0, 0, 8, 0, 0, 0, 0], 10);
let mut commands =
LoadCommandIterator::new(LittleEndian, &Align([0, 0, 0, 0, 8, 0, 0, 0, 0]).0, 10);
assert!(commands.next().is_ok());
}
}
2 changes: 1 addition & 1 deletion src/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//!
//! /// Reads a file and displays the name of each section.
//! fn main() -> Result<(), Box<dyn Error>> {
//! # #[cfg(feature = "std")] {
//! # #[cfg(all(feature = "read", feature = "std"))] {
//! let data = fs::read("path/to/binary")?;
//! let file = object::File::parse(&*data)?;
//! for section in file.sections() {
Expand Down
4 changes: 2 additions & 2 deletions src/write/string.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::vec::Vec;

#[cfg(feature = "std")]
#[cfg(feature = "write_std")]
type IndexSet<K> = indexmap::IndexSet<K>;
#[cfg(not(feature = "std"))]
#[cfg(not(feature = "write_std"))]
type IndexSet<K> = indexmap::IndexSet<K, hashbrown::hash_map::DefaultHashBuilder>;

/// An identifier for an entry in a string table.
Expand Down

0 comments on commit 69d3879

Please sign in to comment.