From 74b16cf1daf97b7707f7247c579673ef6197e74d Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Tue, 20 Jun 2023 10:49:33 +0530 Subject: [PATCH 1/3] fix: improve parsing output of cppcheck cppcheck can produce malformed output which needs to be explicitly handled --- src/cppcheck.rs | 3 ++- src/main.rs | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cppcheck.rs b/src/cppcheck.rs index 4571baf..e29f30c 100644 --- a/src/cppcheck.rs +++ b/src/cppcheck.rs @@ -25,7 +25,8 @@ pub struct Error { #[serde(rename = "@cwe")] pub cwe: Option, pub location: Option>, - pub symbol: Option, + #[serde(default)] + pub symbol: Vec, } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/main.rs b/src/main.rs index fb5d177..c5ca2e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,7 +109,11 @@ fn _main() -> Result<(), Box> { format!( "{} {}", error.id, - error.symbol.unwrap_or_else(|| "".to_string()) + error + .symbol + .get(0) + .map(String::as_str) + .unwrap_or_else(|| "") ) } else { error.msg From 75bd8cbdce7ad94b84dae9ff88a79006c4ea1d65 Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Fri, 23 Jun 2023 11:16:12 +0530 Subject: [PATCH 2/3] fix: set default to C++20 --- .gitignore | 3 ++- analysis_config.json | 1 - src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 analysis_config.json diff --git a/.gitignore b/.gitignore index 202de28..95ab5d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /cppcheck_result.json -/cppcheck_error.xml \ No newline at end of file +/cppcheck_error.xml +analysis_config.json diff --git a/analysis_config.json b/analysis_config.json deleted file mode 100644 index bc6686c..0000000 --- a/analysis_config.json +++ /dev/null @@ -1 +0,0 @@ -{ "files": [ "test.c" ] } diff --git a/src/main.rs b/src/main.rs index c5ca2e4..9caa1d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ fn run_cppcheck<'a>(executable: &str, code_path: impl AsRef, output_path: i // build the command to run command_with_sh .arg("-c") - .arg(format!("{executable} {code_dir} -l 6 --addon=misra --xml --output-file={output_file} {cppcheck_build_dir}")) + .arg(format!("{executable} {code_dir} -l 6 --std=c++20 --addon=misra --xml --output-file={output_file} {cppcheck_build_dir}")) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()); log::debug!("Running cppcheck START :: {:?}", start.elapsed()); From 57b3d761a3341a765bf69e06bb9f53cee235d9bd Mon Sep 17 00:00:00 2001 From: Swarnim Arun Date: Tue, 27 Jun 2023 16:34:07 +0530 Subject: [PATCH 3/3] revert: default to `c11` --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9caa1d2..c5ca2e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ fn run_cppcheck<'a>(executable: &str, code_path: impl AsRef, output_path: i // build the command to run command_with_sh .arg("-c") - .arg(format!("{executable} {code_dir} -l 6 --std=c++20 --addon=misra --xml --output-file={output_file} {cppcheck_build_dir}")) + .arg(format!("{executable} {code_dir} -l 6 --addon=misra --xml --output-file={output_file} {cppcheck_build_dir}")) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()); log::debug!("Running cppcheck START :: {:?}", start.elapsed());