Menu

python exception in MISRA rule 8.12

2019-07-16
2019-08-05
  • Richard Smith

    Richard Smith - 2019-07-16

    I'm receving the follwing execption using MISRA checker in d4d9bb4830a9198c161e82ef81dd1d0d6c6cef92
    I've not yet dug into what source code is generating the exception.

    Traceback (most recent call last):
    File "/usr/bin/misra.py", line 2497, in <module>
    main()
    File "/usr/bin/misra.py", line 2440, in main
    checker.parseDump(item)
    File "/usr/bin/misra.py", line 2280, in parseDump
    self.misra_8_12(cfg)
    File "/usr/bin/misra.py", line 930, in misra_8_12
    if not e_token.previous.str in ',{':
    TypeError: 'in <string>' requires string as left operand, not instance</string></module>

     
  • versat

    versat - 2019-07-17

    Hmm, we could add a sanitiy check to verify that e_token.previous.str really is a string, but i think it would be better to know what caused e_token.previous.str to be no string.
    Is the code compilable? Maybe there is some compiler specific code at that place?

     
  • versat

    versat - 2019-07-17

    I have found code that causes such an exception:

    enum e { e1 = sizeof(int), e2};
    

    This is valid compilable code, but it causes misra.py to throw an exception:

      File "../misra.py", line 2286, in parseDump
        self.misra_8_12(cfg)
      File "../misra.py", line 903, in misra_8_12
        if not e_token.previous.str in ',{':
    TypeError: 'in <string>' requires string as left operand, not instance
    
     
  • versat

    versat - 2019-07-17

    I created a ticket: https://trac.cppcheck.net/ticket/9208
    If you find another maybe similar problematic code we can add it there or create another ticket.

     
  • Richard Smith

    Richard Smith - 2019-07-18

    Yes the code compiles.

    It seems to associated with code that uses this macro.

    enum KernelUnawareISRs
    {
        GPIO_WAKE_IRQ_PRIORITY = (0u >> (8u - __NVIC_PRIO_BITS)),
        MAX_KERNEL_UNAWARE_CMSIS_PRI
    };
    
    Where #define __NVIC_PRIO_BITS          4
    
    is something included from an ARM CMSIS hardware support .h file
    
    The enum is used this way:
    
        NVIC_SetPriority(GPIOWAKE_IRQn, GPIO_WAKE_IRQ_PRIORITY);
    

    I know the (0u >>) looks odd but its part of a general form of computing interrupt prioritys. The 0u could be 1,2,3,... etc.

    If I do a print(e_token.str) when checking the .c file containg this code then GPIO_WAKE_IRQ_PRIORITY is printed before the exception occurs.

     
  • Richard Smith

    Richard Smith - 2019-08-05

    Looks like this got fixed in master. Thank you. Now I can make more progress on moving to newer cppcheck.

     

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.