Scanner c/c++ code failed

Hi
I want ot scanner C/C++ code, but there is error, can you help to check it
Run envrioment as below:
sonarqube-8.1.0.31237
sonar-scanner-4.2.0.1873-windows
build-wrapper-win-x86-64.exe

Information as below after runned sonar-scanner:build-wrapper.txt (2.5 MB) build-wrapper-dump.txt (877.4 KB)
19:23:54.133 INFO: ------------------------------------------------------------------------
19:23:54.134 INFO: EXECUTION FAILURE
19:23:54.134 INFO: ------------------------------------------------------------------------
19:23:54.134 INFO: Total time: 42.396s
19:23:54.197 INFO: Final Memory: 27M/100M
19:23:54.198 INFO: ------------------------------------------------------------------------
19:23:54.198 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: java.lang.IllegalStateException: java.io.UTFDataFormatException: malformed input around byte 19
at com.sonar.cpp.analyzer.AnalysisExecutor.submit(AnalysisExecutor.java:47)
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:367)
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:336)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:212)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: java.io.UTFDataFormatException: malformed input around byte 19
at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:62)
at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:26)
at com.sonar.cpp.plugin.CFamilySensor.lambda$process$4(CFamilySensor.java:380)
at com.sonar.cpp.analyzer.AnalysisExecutor.lambda$submit$0(AnalysisExecutor.java:53)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.io.UTFDataFormatException: malformed input around byte 19
at java.base/java.io.DataInputStream.readUTF(Unknown Source)
at java.base/java.io.DataInputStream.readUTF(Unknown Source)
at com.sonar.cpp.analyzer.Protocol.read(Protocol.java:65)
at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:60)

Hi @yilwhust,

could you please update the SonarCFamily plugin to version 6.6 and rerun the analysis?

Hi Massimo,
I am as your suggestion to updated sonarCFamily plugin to version 6.6, but unfortunately problems still arise.
I suspect whether there is some wrong configuration in my configuration files, so i show you my configuration as below:

  1. The file “sonar.properties” under sonarQube
    sonar.jdbc.username=sonar
    sonar.jdbc.password=sonar
    sonar.jdbc.url=jdbc:postgresql://localhost/sonar
    sonar.sourceEncoding=UTF-8

  2. The file “sonar-scanner.properties” under sonarScanner:
    sonar.jdbc.url=jdbc:postgresql://localhost/sonar
    sonar.jdbc.username=sonar
    sonar.jdbc.password=sonar

  3. The file “sonar-scanner.properties” under souce code:
    sonar.projectKey=ATE
    sonar.projectName=ATE
    sonar.version=0.0.1-SNAPSHOT
    sonar.sources=MiniATE_Code_Framework
    sonar.cfamily.build-wrapper-output=F:/code/MiniATE_Code_Framework/data

  4. Database is postgreSql, and encoding is UTF8

  5. sonarScanner information as below:
    INFO: Scanner configuration file: E:\sonar-scanner-4.2.0.1873-windows\bin…\conf\sonar-scanner.properties
    INFO: Project root configuration file: F:\Mini-ATE-GUI\sonar-project.properties
    INFO: SonarQube Scanner 4.2.0.1873
    INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
    INFO: Windows 7 6.1 amd64

related log as below:

access - 副本.txt (7.8 KB) ce - 副本.txt (1.4 KB) es - 副本.txt (145.9 KB) sonar - 副本.txt (1.6 KB) web - 副本.txt (15.2 KB)

Hi @yilwhust,

these are all server logs, I don’t need them, I need the sonar-scanner output log.

Hi Massimo
sonar-scanner output log as below:
thanks

output.txt (521.9 KB)

Hi @yilwhust,

FYI you are using SonarCFamily 6.5 and not 6.6.

In any case I think that the problem comes from the fact that your code base is not UTF-8, when analyzing F:/code/MiniATE_Code_Framework/03_SystemLIB/libCali/./src/libCaliDPpmu.cpp the analyzer fails because of that. Would it be possible to try to run the analysis on your code base encoded with UTF-8?

Hi Massimo
Can the SonarQube support others encode code, except UTF-8?
can it support GBK , ANSI/OEM?

Hi @yilwhust,

we are using Clang frontend as core of the analyzer which treat source to be utf-8 encoded.

Hi Massimo

I am working in windows system, so OS default encoding code is GBK, I have modify the system encoding as UTF-8.
And same time, modify source code file as UTF-8 format. but same issue still happened.


thanks

Hi @yilwhust,

are you forcing GBK on somewhere in the analysis property?
Not only cpp files should be UTF-8, header files too.

Hi Massimo

encoding is UTF-8 in the analysis property and .cpp and .h file all are UTF-8

thanks

Hi, Massimo
Do you any suggestion about the issue
Maybe there is other steps that we can try to do?

Hi @yilwhust,

could you share the sonar-scanner output log with --debug parameter and everything in UTF-8?

Hi @mpaladin
About UTF-8 issue, we have fixed.
But there is new issue as below, can you help check the issue again

  1. the related log :output.txt (39.5 KB) build-wrapper.txt (430.0 KB) build-wrapper-dump.json.txt (165.5 KB) sonar-project.properties.txt (158 Bytes) sonar-scanner.properties.txt (438 Bytes)

  2. we run command: “build-wrapper-win-x86-64.exe --out-dir data make clean all” to create files “build-wrapper-dump.json” and “build-wrapper.log”

  3. there is information in “C/C++/Objective-C analysis source code explaination” as below, so do we need any additional configuration?

  4. Error infromation as below:
    15:21:06.672 ERROR: Error during SonarQube Scanner execution
    java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sur
    e that:

  • you are using the latest version of the build-wrapper and the SonarCFamily analyzer
  • you are correctly invoking the scanner with correct configuration * your compiler is supported
  • you are wrapping your build correctly
  • you are wrapping a full/clean build
  • you are providing the path to the correct build-wrapper output directory
    at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:356)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Hi @yilwhust,

it’s because you are building in D:\\sonar\\ATE_project\\MiniATE_Code_Framework and analyzing in a different drive: Z:\sonar\ATE_project\MiniATE_Code_Framework. Notice D and Z.

You should build and analyze on the same paths in order for the analyzer to be able to match files.

Hi @mpaladin
Pleasue to received your reponse, thanks for you help to check the issue.
I create a simple project that verify the sonarQube test framework in my local envrionment.
First, as your suggestion, i build and analyze on the same path
But the same issue still happened, detail log as below:
build-wrapper.txt (40.3 KB) build-wrapper-dump.json.txt (34.9 KB) output.txt (26.0 KB) sonar-project.properties.txt (129 Bytes)

Hi @yilwhust,

I don’t see any max.c file compilation in the build-wrapper-dump.json file which explains why 0 compilation units are analyzed.

Hi @mpaladin
I don’t understand “I don’t see any max.c file compilation”, i run the build command, and can see the project have build successfully as below:
cmd

 If need, i can share you the simple the project, code as below:
  1. max.c

#include “max.h”
int max(int a, int b)
{
return a > b ? a : b;
}


  1. max.h

int max(int a, int b);


  1. max_num.c

#include <stdio.h>
#include <stdlib.h>
#include “max.h”

int main(void)
{
printf(“The bigger one of 3 and 5 is %d\n”, max(3, 5));
system(“pause”);
return 0;
}


  1. makefile

max_num.exe:max_num.o max.o
gcc -o max_num.exe max_num.o max.o

max_num.o:max_num.c max.h
gcc -c max_num.c

max.o:max.c max.h
gcc -c max.c

clean:
rm *.o


Hi @yilwhust,

you may be affected by CPP-1249.