Menu

False positive on Misra 10.3 for bools

Andreas
2023-10-20
2023-10-25
  • Andreas

    Andreas - 2023-10-20

    For my c11 project I get false positives on MISRA 10.3 (The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category) when assigning true or false to a boolean variable.
    I suppose this is because stdbool.h defines:

    #define true 1
    #define false 0
    

    Which makes true and false essentially signed integers.

    Here some example code:

    #include <stdbool.h>
    
    bool dummy_func(int val)
    {
      bool my_bool;
      if (val > 10)
      {
        my_bool = true;   // Triggers warning for MISRA 10.3
      }
      else
      {
        my_bool = false;   // Triggers warning for MISRA 10.3
      }
      return my_bool;
    }
    

    I am running cppcheck from the GUI and I cannot find a setting for which c standard I use - in case that is the problem.

     
  • Andreas

    Andreas - 2023-10-25

    After writing the above I did find the setting for C-standard in the GUI. However, the problem still remains.

     

    Last edit: Andreas 2023-10-25

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.