C6305 is reported in VS2019 but not in VScode for same source code

Windows 11, Visual studio 2019 and Visual studio code

I have the same code in both IDEs:

typedef struct {
    int a;
} element_t;

typedef struct {
    int idx;
    element_t a1;
    element_t a2;
    element_t a3;
} elementes_t;

elementes_t myElements;
element_t* pelement_t = (&myElements.a1 + sizeof(element_t) * 4);
pelement_t->a = 1;

In VS2019, SonarLint underlines the addition of sizeof with error C6305, but same code in Visual Studio Code results without any errors.
Is this a configuration issue?

Hi,

Welcome to the community!

What versions of SonarLint are you using in each IDE?

 
Ann

VSC 1.80.1 SonarLint v3.19.2
VS2019 16.11.27 SonarLint 7.0.0.74072

Hi,

Thanks for the verification. I’ve flagged this for the relevant experts.

 
Ann

1 Like

Hello @Evgeny_Erlihman.

It might be a configuration problem. First, try to check if you have all set for C/C++ analysis.
If everything is good there - please provide the SonarLint output that comes when you open C/C++ files.

Have a good day!

Here is the output:

Executing /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/jre/17.0.7-linux-x86_64.tar/bin/java -jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/server/sonarlint-ls.jar -stdio -analyzers /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonargo.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarjava.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarjs.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarphp.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarpython.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarhtml.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarxml.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonarcfamily.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonartext.jar /root/.vscode-server/extensions/sonarsource.sonarlint-vscode-3.19.2-linux-x64/analyzers/sonariac.jar

[Warn - 12:01:37.296] Using ${workspaceFolder} variable in sonarlint.pathToCompileCommands is only supported for files in the workspace

[Info - 12:01:37.421] Analyzing file 'path/filename.cpp'...

[Info - 12:01:43.650] Found 4 issues

[Info - 12:01:43.675] Analyzing file 'path/.vscode/c_cpp_properties.json'...

[Info - 12:01:43.824] Found 0 issues

[Warn - 12:09:26.617] Using ${workspaceFolder} variable in sonarlint.pathToCompileCommands is only supported for files in the workspace

[Debug - 12:09:28.565] Fetching global configuration

[Warn - 12:09:28.567] Using ${workspaceFolder} variable in sonarlint.pathToCompileCommands is only supported for files in the workspace

[Debug - 12:09:28.567] Fetching configuration for folder 'path'

[Debug - 12:09:28.569] Global settings updated: WorkspaceSettings[connections={},disableTelemetry=false,excludedRules=[],includedRules=[],pathToNodeExecutable=,ruleParameters={},showAnalyzerLogs=true,showVerboseLogs=true]

So I do see other issues, but not this one…

Hi @Evgeny_Erlihman,

C6305 Warning C6305 | Microsoft Learn is a VisualStudio compiler warning and not an issue raised by SonarLint. They usually start with capital C. something like Cxxxx.

SonarLint issues for C&C++ look like c:Sxxxx and cpp:Sxxxx. The language + : + S + number. When you click on them in Visual Studio, they should show the Sonar Rules description.

while something like C6305 will direct you to the Microsoft website.

That is why you don’t see C6305 in VS Code; it is simply not raised by SonarLint.

Thanks,

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.