QiuminGe / cpp-check-lint

MIT License
12 stars 6 forks source link

misra.py addon not working correctly #51

Open belliriccardo opened 1 day ago

belliriccardo commented 1 day ago

Hi! I'm having trouble making the extension work with the "misra.py" addon. Before the latest updates (before 1.5.2) I had the settings (in settings.json) like this: image But that doesn't work anymore: image So (temporarily) I hardcoded the full path of the plugin (C:\\Users\\riccardo.b\\.vscode\\extensions\\qiumingge.cpp-check-lint-1.5.4\\bin\\win64\\addons\\misra.py), and I tried running it again but it still fails to catch very simple misra errors. I then wondered if the python file actually got executed, so I went and modified it like so: image I just added a small print (there are many throughout the code) and like this I get this error message when trying to analyze a single file (with right click -> cpp-check-lint -> cppcheck-file).

CWE-0 Bailing out from analysis: Whole program analysis failed: Failed to execute 'python3.exe  C:\Users\riccardo.b\.vscode\extensions\qiumingge.cpp-check-lint-1.5.4\bin\win64\addons\misra.py --cli --rule-texts=c:/DATI/REPO/PROJECT_NAME/misra-rules-2012.txt --file-list c:\DATI\REPO\PROJECT_NAME\src\cppcheck-addon-ctu-file-list13840'. TEST

So the "TEST" gets printed but the whole program then gets aborted? Also It seems that there is some sort of problem when selecting a single file, as I don't think that the --file-list argument is correct. It would also be nice to go back to selecting the addon with just the relative path (misra.py instead of C:\\Users\\riccardo.b\\.vscode\\...), I don't know what happened there honestly.

QiuminGe commented 1 day ago

is ok before 1.5.2?

belliriccardo commented 1 day ago

UPDATE: I tried running the same command run by the plugin in a cmd shell, and I get the following: image Weird.. adding an actual misra.json file containing the following content I get a bit further: image (I pass --addon=C:/path/to/misra.json instead of the actual json itself). Like this I get a bit further, and I get one problem detected by Cppcheck itself, but not misra.py: image I tried adding a print("TEST") again right before the main in the script and this is what I get instead: image Which inside of VSCode gets translated as the error message that I posted about earlier: image

belliriccardo commented 1 day ago

is ok before 1.5.2?

Sorry I wrote my message before I saw this reply; I was using quite often for misra checks in my code and I didn't notice any particular problems.

belliriccardo commented 1 day ago

I have an update, I managed to get the plugin to work manually by creating a .bat like so (inspired from this):

"C:/Program` Files/Cppcheck/cppcheck.exe" --verbose --dump --template={file}:{line}:{column}: {severity}: CWE-{cwe} {message}:[{id}] --enable=warning -j1 --max-ctu-depth=2 --platform=native --std=c99 --std=c++03 --inline-suppr --report-progress <includes here> --suppress=misra-c2012-2.5 --suppress=misra-c2012-2.4 --suppress=misra-c2012-8.9 --suppress=misra-c2012-19.2 <predefined symbols here> c:\DATI\REPO\PROJECT_NAME\src\main.c
pause
python "C:/Program Files/Cppcheck/addons/misra.py" --rule-texts=misra-rules-2012.txt src/main.c.dump

Like this I managed to get the following output: image Which is the correct output for the file at hand.

QiuminGe commented 1 day ago

C:/Program` Files/Cppcheck/cppcheck.exe --- whcih version?

Cppcheck 2.15 (open source) http://cppcheck.net/

image

https://files.cppchecksolutions.com/manual.pdf

image

It feels like Misra has been migrated to Premium features.

belliriccardo commented 23 hours ago

So I have version 2.15, but I also have the rules file, so I should be good. Meaning, the program works providing the misra-rules-2012.txt to the program. I don't think that's the issue. You can see in my previous post that the program correctly runs and I get the correct output:

I have an update, I managed to get the plugin to work manually by creating a .bat like so (inspired from this):

"C:/Program` Files/Cppcheck/cppcheck.exe" --verbose --dump --template={file}:{line}:{column}: {severity}: CWE-{cwe} {message}:[{id}] --enable=warning -j1 --max-ctu-depth=2 --platform=native --std=c99 --std=c++03 --inline-suppr --report-progress <includes here> --suppress=misra-c2012-2.5 --suppress=misra-c2012-2.4 --suppress=misra-c2012-8.9 --suppress=misra-c2012-19.2 <predefined symbols here> c:\DATI\REPO\PROJECT_NAME\src\main.c
pause
python "C:/Program Files/Cppcheck/addons/misra.py" --rule-texts=misra-rules-2012.txt src/main.c.dump

Like this I managed to get the following output: image Which is the correct output for the file at hand.

QiuminGe commented 5 hours ago

image

image

belliriccardo commented 2 hours ago

Hmmm, could you share more info about your setup? Also which python version are you using?