Menu

how to write .cfg files checking class member functions

baosj0
2023-01-06
2023-01-08
  • baosj0

    baosj0 - 2023-01-06

    thanks for your help!!!!!!!
    i wanna check a class member function, how do I write .cfg files?
    for example,

    class objtest
    {
    public:
             char * _itoa (int value, char * str, int base);
    };
    
    int main()
    {
       objtest obj;
      char temp[20] = {0};
       obj._itoa(44,temp,55); // this won't report error using cfg files below.
       itoa(44,temp,55);     // but this will, using default std.cfg.
    }
    
    with cfg files:
    <?xml version="1.0"?>
    <def format="2">
     <define name="uint8" value="unsigned char"/>
      <!-- Not part of standard, but widely supported by runtime libraries. -->
      <!-- char * _itoa (int value, char * str, int base); -->
      <function name="objtest::_itoa">
        <noreturn>false</noreturn>
        <leak-ignore/>
        <returnValue type="char *"/>
        <arg nr="1" direction="in">
          <not-uninit/>
        </arg>
        <arg nr="2" direction="out">
          <not-null/>
        </arg>
        <arg nr="3" direction="in">
          <not-uninit/>
          <valid>2:36</valid>
        </arg>
      </function>
    </def>
    

    I wanna know how to write this cfg files???

     
  • Daniel Marjamäki

    If you comment out the class declaration it works:

    /*
    class objtest
    {
    public:
             char * _itoa (int value, char * str, int base);
    };
    */
    int main()
    {
       objtest obj;
       char temp[20] = {0};
       obj._itoa(44,temp,55); // this won't report error using cfg files below.
    //   itoa(44,temp,55);     // but this will, using default std.cfg.
    }
    

    I get this warning then:

    1.cpp:12:22: error: Invalid obj._itoa() argument nr 3. The value is 55 but the valid values are '2:36'. [invalidFunctionArg]

    One current rule is that cppcheck does not use the configuration if the function declaration is seen. We need to have that rule for "external" functions like the standard functions. Is objtest::_itoa some "external" function in your case or something that you wrote yourself?

    I believe we have some ticket in trac to add some mechanism in the cfg file so users can choose if configurations should be skipped when function declaration is seen or not. We want to skip the configuration in all the files we distribute I believe but users might often want to use their configurations.

     

    Last edit: Daniel Marjamäki 2023-01-07
    • baosj0

      baosj0 - 2023-01-08

      objtest::_itoa just like normal itoa function, and its code is in another cpp file.
      I'll try your way to test our code. It's old and very big.
      thanks a lot!

       

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.