Menu

Disable std.cfg automatically loaded

2024-12-01
2024-12-06
  • André Coquim

    André Coquim - 2024-12-01

    Context:
    * I'm using Cppcheck 2.13.0
    * I'm trying to run cppcheck on a cross-compiled project, so I do not use the default system includes
    * After reading some documentation and code in the github repository I found that "configuration for the standard libraries of C and C++, std.cfg, is always loaded by cppcheck".

    Problem:
    I'm trying to get rid of the missingIncludeSystem the correct way which is by specifying the paths for the files/dirs, instead of using the --supress=missingIncludeSystem. In some files where I am able to achieve this I even get new code warnings, which is a good thing, but as a result I get false syntax error in some system include files like math.h.
    I understood that this is due to the load of some configurations present in file cppcheck/cfg/ std.cfg that conflict with the cross-tools header files.

    As an example:

    This enum exists in my cross-compilation math.h file:

    enum
      {
        FP_NAN =
    # define FP_NAN 0
          FP_NAN,
        FP_INFINITE =
    # define FP_INFINITE 1
          FP_INFINITE,
        FP_ZERO =
    # define FP_ZERO 2
          FP_ZERO,
        FP_SUBNORMAL =
    # define FP_SUBNORMAL 3
          FP_SUBNORMAL,
        FP_NORMAL =
    # define FP_NORMAL 4
          FP_NORMAL
      };
    

    When I run cppcheck with preprocessor:
    cppcheck math.h -E

    I can see that the result becomes:

    enum
    {
     5 =
    
     0 ,
     4 =
    
     1 ,
     3 =
    
     2 ,
     2 =
    
     3 ,
     1 =
    
     4
    } ;
    

    The correct result should be:

    enum
      {
        FP_NAN =
    
          0,
        FP_INFINITE =
    
         1,
        FP_ZERO =
    
          2,
        FP_SUBNORMAL =
    
         3,
        FP_NORMAL =
    
          4
      };
    

    This happens because std.cfg is being loaded with this configurations:

    <define name="FP_NORMAL" value="1"/>
      <define name="FP_SUBNORMAL" value="2"/>
      <define name="FP_ZERO" value="3"/>
      <define name="FP_INFINITE" value="4"/>
      <define name="FP_NAN" value="5"/>
    

    Consequently it results in syntax error detected by cppcheck when analyzing the file or any file that includes it!

    math.h:915:3: error: syntax error: 5 = [syntaxError]
    

    What I propose here is for cppccheck not load anything automatically or to create a new cppcheck flag to not load any config file automatically, for example: --no-auto-config

    Thanks

     

    Last edit: André Coquim 2024-12-01
  • CHR

    CHR - 2024-12-06

    Not loading std.cfg is really not advisable due to the information about library functions etc. that it contains. In your case, couldn't you use a patched .cfg without the offending values?

     
  • André Coquim

    André Coquim - 2024-12-06

    To prove everything I said I have changed the content of std.cfg to make it "empty":

    <?xml version="1.0"?>
    <def format="2">
    </def>
    

    This solved the problem, but I was using a version that I downloaded personally for me.
    In a corporative environment I don't have root privileges in the machine so I cannot do such a thing. Also, each time Cppcheck is upgraded the same fix is needed and this approach is not convenient since I don't have root privileges.
    I understand that not loading by default may not be advisable, but that's why I proposed a new flag like --no-auto-config to be able to not load this file as an option.

    Thanks

     

    Last edit: André Coquim 2024-12-06
  • CHR

    CHR - 2024-12-06

    Using --supress=missingIncludeSystem is the way to go, making standard headers visible to cppcheck serves no purpose. That's why std.cfg exists.

     

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.