Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MISRA C 2012 Amendment 1 rules supported by PC-Lint #1856

Closed
farshield opened this issue Apr 28, 2020 · 8 comments
Closed

Add MISRA C 2012 Amendment 1 rules supported by PC-Lint #1856

farshield opened this issue Apr 28, 2020 · 8 comments
Assignees
Milestone

Comments

@farshield
Copy link

farshield commented Apr 28, 2020

There is no definition for MISRA 2012 Rule 21.15, however a similar rule called "L0857" exists.
If I submit the following report to Sonarqube, the issue is ignored and can not be seen in "code smells":

<?xml version="1.0" ?>
<results>
 <issue file ="mytest.c" line = "254" number = "857" desc = "argument 1 of type &apos;uint8_t *&apos; (aka &apos;unsigned char *&apos;) is not compatible with argument 2 of type &apos;const void *&apos; in call to function &apos;memcpy&apos; [MISRA 2012 Rule 21.15, required]"/>
</results>

However, if I remove the text "Rule 21.15" from the description field of the XML file and submit the report again, I'm able to see the issue in Sonarqube under L0857.

I created a custom rule with the key "M2012_21_15" and then changed the key in Postgresql to "M2012-21.15". I had to do this hack because of input validation when creating the key - I could not use special characters like the dash or the dot so I had to rename it from the database. I labeled it "misrac3" after that.

Once I renamed the key I was able to report the issue and see it in Sonarqube.

Sorry for the offtopic: The best approach would be to add it to the plugin, but in the meantime is there an easier way to rename the key? Especially if I'm using H2 databases (I wasn't able to rename it from H2).

  • cxx plugin version: v1.3.2
  • SonarQube version: 7.9 LTS
@guwirth
Copy link
Collaborator

guwirth commented Apr 28, 2020

Hello @farshield,

Which tool to create the messages are you using?
Which sensor are you using to read the report?
Please provide the relevant parts of your config file.

Regards,

@guwirth guwirth self-assigned this Apr 29, 2020
@farshield
Copy link
Author

farshield commented Apr 29, 2020

Hello @guwirth,

I'm using PC-Lint Plus v1.3 to create the XML report and use the PCLintSensor (INFO: Sensor C++ (Community) PCLintSensor [cxx] (done) | time=97ms).

For the sonar-scanner I'm using (v4.3.0.2102-linux), I added the following lines to the "sonar-project.properties" file:

sonar.projectKey=myproject
sonar.projectName=myproject
sonar.language=c++
sonar.sources=lib
sonar.tests=tests
sonar.c.includeDirectories=lib
sonar.cxx.coverage.reportPath=build/gcovr-report.xml
sonar.cxx.pclint.reportPath=build/pclint-report.xml

Regards

@guwirth
Copy link
Collaborator

guwirth commented Apr 29, 2020

Hello @farshield ,

I need some more time to verify this, but maybe you can have a look by yourself:

Code of sensor:
https://github.com/SonarOpenCommunity/sonar-cxx/blob/cxx-1.3.2/cxx-sensors/src/main/java/org/sonar/cxx/sensors/pclint/CxxPCLintSensor.java

Available rules:
https://github.com/SonarOpenCommunity/sonar-cxx/blob/cxx-1.3.2/cxx-sensors/src/main/resources/pclint.xml

Maybe rule is missing? Parsing is wrong...

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Apr 29, 2020

@farshield looking into pclint.xml there is no item <key>M2012-21.15</key>. Means the messages are not up to date.

For my understanding new rules of

  • MISRA C:2012 Amendment 1
  • MISRA C:2012 Addendum 2
  • MISRA C:2012 Addendum 3

are missing?

@farshield can you provide these new rules / extend the XML file?
https://github.com/SonarOpenCommunity/sonar-cxx/blob/cxx-1.3.2/cxx-sensors/src/main/resources/pclint.xml

Misra publications:
https://www.misra.org.uk/Publications/tabid/57/Default.aspx

@guwirth guwirth changed the title MISRA 2012 Rule 21.15 missing PC-Lint MISRA 2012 rules missing: Amendment 1, Addendum 2, Addendum 3 Apr 29, 2020
@farshield
Copy link
Author

farshield commented Apr 29, 2020

@guwirth Indeed this is the case, the rules for MISRA C 2012 AMD-1 are missing. I will try to create first a list of missing rules. Then I will try to add them to the XML file and create a PR if nobody else will create the PR before.

Later edit:
The following rules supported by PC-Lint are missing from the XML file:

  • Rule 12.5
  • Rule 21.13
  • Rule 21.15
  • Rule 21.16
  • Rule 21.17
  • Rule 21.18

@guwirth
Copy link
Collaborator

guwirth commented May 1, 2020

@farshield

The following rules supported by PC-Lint are missing from the XML file

Means there are more MISRA C 2012 rules missing in the XML but these are not supported by PC-Lint?

@farshield
Copy link
Author

@guwirth

Correct. Here is a list of MISRA C 2012 AMD-1 supported rules found in the documentation of the latest PC-Lint Plus (v1.3.5-beta):

image

@guwirth guwirth assigned farshield and unassigned guwirth May 1, 2020
@guwirth guwirth added this to the 2.0.0 milestone May 1, 2020
@guwirth guwirth changed the title PC-Lint MISRA 2012 rules missing: Amendment 1, Addendum 2, Addendum 3 Add MISRA C 2012 Amendment 1 rules supported by PC-Lint May 1, 2020
@guwirth
Copy link
Collaborator

guwirth commented May 1, 2020

closed with #1857

@guwirth guwirth closed this as completed May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants