Menu

misra check crashing during misra_20_9 check

5 days ago
4 days ago
  • Peter Schops

    Peter Schops - 5 days ago

    when you have the following in the code, the misra check crashes in the misra_20_9 check

    #define bad_define
    #define correct_define 1
    
    #if bad_define
      printf ("will crash the misra check\n");
    #endif
    
    #if correct_define
       printf ("Hello\n");
    #endif
    

    I managed to fix the code by adding an extra escape in misra.py. This way we don't try to access s[0] after the cond.E.split

        def misra_20_9(self, cfg):
            for cond in cfg.preprocessor_if_conditions:
                if cond.E is (None or u""):
                    continue
    

    I found it also strange that misra_20_8 is not flagging this line. bad_define is assinged no value. So how can cond.result evaluate to 0 or 1. (0 in this case)
    To get the attention I added some extra condition to set misra_20_8, which is probably not totally correct.

        def misra_20_8(self, cfg):
            for cond in cfg.preprocessor_if_conditions:
                if cond.E is (None or u""):
                    self.reportError(cond, 20, 8)
                if cond.result and cond.result not in (0,1):
                    self.reportError(cond, 20, 8)
    
     
  • Daniel Marjamäki

    Feel free to create a PR. I will not do any more active work on misra.py.. but will be happy to review/merge PRs that fix misra.py bugs.

    We provide better Misra checking in Cppcheck Premium.

     

Log in to post a comment.