Menu

improvements in misra.py

vix
2021-07-15
2021-07-19
  • vix

    vix - 2021-07-15

    I tried to use misra.py and I noticed one unexpected behaviors, together with some possible improvements.
    I would have opened pull requests, but in the github repository is not possible.
    So I'm going to describe here what I found.

    First of all I try to describe the unexpected behavior:
    If I use misra.py without a rule-texts file, it found 7 violations in my source code.
    When I passed a rule-texts file to the command line., 0 violations were found on the same source code.
    And so I investigated what happened.
    Probably my rule-texts file was a little bit old, and so some of the rules checked in the misra.py script don'h have a description in the rule-texts file.
    If this happens, this branch of if/elif/else is taken
    https://github.com/danmar/cppcheck/blob/cbb07b6247ed9b6c85766b12011ffc783f5b7626/addons/misra.py#L3301
    and so the violation is not counted.
    I think that the return is wrong.
    I suggest to set properly errmsg (as an example errmsg = f'misra violation nr {ruleNum} not found in rule-texts-file') as it's done when a rule-texts file is not provided
    https://github.com/danmar/cppcheck/blob/cbb07b6247ed9b6c85766b12011ffc783f5b7626/addons/misra.py#L3299

    Now I add some possible improvements (based on what I found):
    * I see that a_z_pattern is used to match the additional lines of rule text. Since these lines can start with a capital letter too, I suggest to change https://github.com/danmar/cppcheck/blob/cbb07b6247ed9b6c85766b12011ffc783f5b7626/addons/misra.py#L3328 into a_z_pattern = re.compile(r'^[A-z].*')

    Thanks in advance for the job

     
  • Georgiy Komarov

    Georgiy Komarov - 2021-07-15

    Hello,

    Thanks, your suggestion with handling incorrect rules texts seems reasonable to me. Why can't you create a PR? The github repository you mention accepts pull requests.

    I'm not sure about a_z_pattern. The point is that the lines from the rules texts correctly generated from the MISRA2012 document always start with a lowercase symbol if they are a continuation of the rule description. But changing this pattern to another one (I suggest r'^[a-zA-Z].*' then) won't break anything, so, I think, it is acceptable too.

     
  • vix

    vix - 2021-07-19

    I've just opened a pull request in github with the above proposed changes.

     
  • vix

    vix - 2021-07-19

    One more thing:
    I see the example for the MISRA_C_2012.txt text file
    https://github.com/danmar/cppcheck/blob/d1fe34e1677e63735e694152a5e863118e288d99/addons/misra.py#L3841-L3849

    I don't see how the tags (Required | Mandatory | Advisory) should be written in the file

    I suppose
    either
    Rule 1.1 (Required)
    or

    Rule 1.1
    (Required)
    

    Can you clarify, please?
    Then I can add this info to my pull request too.

     
  • Daniel Marjamäki

    Yes without the parentheses. both should work..

    Rule 1.1 Required
    

    or

    Rule 1.1
    Required
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.