SonarLint analyze C/C++ code but output "found 0 issue" even if there are issues

Please provide

  • Operating system:
  • SonarLint plugin version:
  • Programming language you’re coding in:
  • Is connected mode used:
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

I have a C code which supposedly output some issue or error when analyze, instead it gives me this output;

[Debug - 13:43:46.556] Start analysis
[Info - 13:43:46.672] Index files
[Debug - 13:43:46.674] Language of file "file:///c:/Users/razile/Desktop/FOR%20TESTING/sample.c" is set to "C"
[Info - 13:43:46.712] 1 file indexed
[Debug - 13:52:57.797] Loading C:\Users\razile\AppData\Local\Temp\sonarsource-cfamily-jni480016664403011628.dll
[Debug - 13:43:46.874] Added 253 checks for language='ts', repository='typescript'
[Debug - 13:43:46.884] Added 252 checks for language='js', repository='javascript'
[Debug - 13:43:46.935] 'JavaSensor' skipped because there is no related files in the current project
[Debug - 13:43:46.935] 'Python Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.935] 'IPython Notebooks Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.935] 'OmniSharp' skipped because there is no related files in the current project
[Debug - 13:43:46.935] Execute Sensor: HTML
[Debug - 13:43:46.935] 'XML Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.935] 'Code Quality and Security for Go' skipped because there is no related files in the current project
[Debug - 13:43:46.935] 'PHP sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.935] 'Analyzer for "php.ini" files' skipped because there is no related files in the current project
[Debug - 13:43:46.936] 'IaC Terraform Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.936] 'IaC CloudFormation Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.936] 'IaC Kubernetes Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.936] 'IaC AzureResourceManager Sensor' skipped because there is no related files in the current project
[Debug - 13:43:46.936] Execute Sensor: TextAndSecretsSensor
[Info - 13:43:47.220] 1 source file to be analyzed
[Info - 13:43:47.221] 1/1 source file has been analyzed
[Debug - 13:43:47.222] 'JavaScript/TypeScript analysis' skipped because there is no related files in the current project
[Debug - 13:43:47.224] 'JavaScript inside YAML analysis' skipped because there is no related files in the current project
[Debug - 13:43:47.224] 'JavaScript inside HTML analysis' skipped because there is no related files in the current project
[Debug - 13:43:47.224] Execute Sensor: CSS Rules
[Info - 13:43:47.225] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[Debug - 13:43:47.225] Execute Sensor: IaC Docker Sensor
[Info - 13:43:47.262] 0 source files to be analyzed
[Info - 13:43:47.262] 0/0 source files have been analyzed
[Debug - 13:43:47.262] Execute Sensor: CFamily
[Debug - 13:43:47.292] Cached compilation database modified time did not change
[Debug - 13:43:47.292] Time to parse Compilation Database: 0ms
[Info - 13:43:47.294] Subprocess(es) done in 31ms
[Info - 13:43:47.294] 0 compilation units analyzed
[Info - 13:43:47.314] Found 0 issues

Hey there.

Have you followed the documentation to hook up a compilation database?

Hi, I actually did. I manually created the compile_commands.json into the same directory of the C file and then configure the settings.json; Here’s the compile_commands.json
[ { "directory": "C:/Users/razile/Desktop/FOR TESTING", "command": "gcc -c C:/Users/razile/Desktop/FOR TESTING/sample.c -o C:/Users/jimenez.el/Desktop/FOR TESTING/sample.o", "file": "C:/Users/razile/Desktop/FOR TESTING/sample.c" } ]

Here is the setting.json that I configured;

{ "workbench.colorTheme": "Default Dark Modern", "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }, "explorer.confirmDelete": false, "workbench.iconTheme": "vs-minimal", "editor.renderWhitespace": "all", "sonarlint.focusOnNewCode": false, "sonarlint.rules": { "c:S2260": { "level": "on" }, }, "cmake.configureOnOpen": true, "sonarlint.ls.javaHome": "C:/Program Files/Java/jdk-20", "sonarlint.pathToCompileCommands": "C:\\\\Users\\\\razile\\\\Desktop\\\\FOR TESTING\\\\compile_commands.json", "workbench.settings.applyToAllProfiles": [ "sonarlint.pathToCompileCommands", "sonarlint.output.showAnalyzerLogs" ], "sonarlint.analyzerProperties": { "sonar.cfamily.reproducer" : "C:\\Users\\razile\\Desktop\\FOR TESTING\\sample.c" }, "sonarlint.output.showAnalyzerLogs": true, "sonarlint.output.showVerboseLogs": true, }

Hey @Razile , welcome to Sonar Community! :wave: :sonar:

I have a C code which supposedly output some issue or error when analyze

Why is the code supposed to raise an error? Would you be able to provide a reproducer/sample maybe? According to the logs, the analysis is run successfully and there are no issues found.

Also, it would help if you could provide the required information that is blank in the beginning of your post (at least SonarLint plugin version).

All the best,
Sophio :blush:

Hi, after I installed the SonarLint in VS Code I tried it with simple C code but it didn’t analyze the C code, so I looked at the documentation and requirements to run analysis and then tried it again but still nothing.

I purposely raise an error so that I’ll know it analyze the code, as part of investigation. I tried to pick some rules and create a non-compliant code sample according to that rule to check it.

  • Operating system: Windows 10 Pro version 22H2
  • SonarLint plugin version: v4.3.0
  • Programming language you’re coding in: C Language
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version): N/A

Thank you for the details! :bowing_woman:

I manually created the compile_commands.json into the same directory

This could be the cause of why the analyzer is not able to detect an issue. The analyzer needs a compilation command that works since it needs to run the compiler to probe it. And, ideally, the actual command you use to compile.

If you use CMake, we would suggest you let it generate the configuration database.

Let us know how it goes,
Sophio

It is working now, sorry for the late response. Thank you!

1 Like