Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ You can also do the same with files as the following:
IGNORED_FILES=./src/tests/something.rs,./src/tests/else.rs cargo panic-analyzer > audit.md
```

For ignoring crates that only use array indexing without triggering other audits define the `IGNORE_ARRAY_INDEX_ONLY_CRATES`` environment variable.

```sh
IGNORE_ARRAY_INDEX_ONLY_CRATES=1 cargo panic-analyzer > audit.md
```

A potential panic is not necessarily bad, sometimes errors are unrecoverable, and we have to panic.
If your panic is intentional, you can add a comment before the line that has the potential panicing code like this:

Expand Down
24 changes: 14 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fn main() -> io::Result<()> {
.map(|s| s.to_string())
.collect::<HashSet<String>>();

let ignore_array_index_only_crates = std::env::var("IGNORE_ARRAY_INDEX_ONLY_CRATES").is_ok();

let mut crate_counts: HashMap<String, HashMap<&str, (usize, String)>> = HashMap::new();
let mut expected_annotations: HashMap<String, Vec<(String, String, String)>> = HashMap::new();

Expand Down Expand Up @@ -143,16 +145,18 @@ fn main() -> io::Result<()> {
}
}

// adjust counts for crates with only 'array_index' errors
for pattern_counts in crate_counts.values_mut() {
let only_array_index_errors = pattern_counts
.iter()
.all(|(pattern, &(count, _))| *pattern == "array_index" || count == 0);

if only_array_index_errors {
if let Some((count, _)) = pattern_counts.get_mut("array_index") {
total_actual_audits = total_actual_audits - *count;
*count = 0;
if ignore_array_index_only_crates {
// adjust counts for crates with only 'array_index' errors
for pattern_counts in crate_counts.values_mut() {
let only_array_index_errors = pattern_counts
.iter()
.all(|(pattern, &(count, _))| *pattern == "array_index" || count == 0);

if only_array_index_errors {
if let Some((count, _)) = pattern_counts.get_mut("array_index") {
total_actual_audits = total_actual_audits - *count;
*count = 0;
}
}
}
}
Expand Down