Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Add clippy Workflow #2

Merged
merged 3 commits into from
Jun 9, 2024
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.78.0

permissions:
contents: read
Expand All @@ -30,7 +31,7 @@ jobs:
static.rust-lang.org:443
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=${{ env.RUST_VERSION }} -y
export PATH="$HOME/.cargo/bin:$PATH"
rustup default stable
rustup component add rustfmt
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/rust-clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: rust-clippy

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '40 12 * * 6'

env:
RUST_VERSION: 1.78.0

jobs:
rust-clippy:
name: Run rust-clippy
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
with:
egress-policy: audit
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- name: Install Rust toolchain
run: |
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=${{ env.RUST_VERSION }} -y
export PATH="$HOME/.cargo/bin:$PATH"
rustup default stable
rustup component add clippy

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt

- name: Run rust-clippy
run:
cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@8f1a6fed33af5212fab8a999d004627ae8901d1b
with:
sarif_file: rust-clippy-results.sarif
wait-for-processing: true
21 changes: 10 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::fmt::Write;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
use std::process;
Expand Down Expand Up @@ -30,10 +31,10 @@ fn main() {
}

let magic = &header[..4];
let magic_string = magic
.iter()
.map(|b| format!("{:02X}", b))
.collect::<String>();
let magic_string = magic.iter().fold(String::new(), |mut result, b| {
let _ = write!(result, "{b:02X}");
result
});

// Check if the file is an ELF file
if magic != ELF_MAGIC {
Expand Down Expand Up @@ -311,9 +312,9 @@ fn get_segment_type(segment_type: u32) -> &'static str {
fn get_segment_flags(segment_flags: u32) -> String {
let mut flags = String::new();
match segment_flags {
0x01 => flags.push_str("R"),
0x02 => flags.push_str("W"),
0x04 => flags.push_str("X"),
0x01 => flags.push('R'),
0x02 => flags.push('W'),
0x04 => flags.push('X'),
_ => flags.push_str("Unknown"),
}
flags
Expand Down Expand Up @@ -367,11 +368,9 @@ fn get_data_encoding(header: &[u8]) -> (String, u8) {
}

fn bits_to_u16(bits: &[u8; 2]) -> u16 {
let value = u16::from_le_bytes(*bits);
value
u16::from_le_bytes(*bits)
}

fn get_elf_version(header: &[u8]) -> u8 {
let elf_version = header[0x06];
elf_version
header[0x06]
}