Menu

Specify macros as functions in cfg file

2015-09-22
2015-09-23
  • Justin Dailey

    Justin Dailey - 2015-09-22

    I'm trying to get this to report a memory leak...

    void the_function (char *buffer);
    
    #define the_macro       the_function
    
    int main(int argc, char *argv[]) {
        char *c = (char*) malloc(10);
        the_macro(c);
        return 0;
    }
    

    Given:

    <?xml version="1.0"?>
    <def format="2">
        <function name="the_macro">
            <noreturn>false</noreturn>
            <leak-ignore/>
            <arg nr="1">
                <not-null/>
            </arg>
        </function>
    </def>
    

    As you can see, I am specifying in the library configuration that "the_macro" has the leak-ignore flag. Is this a limitation of CppCheck, or is there some other way around this? I am aware that if I change the 3rd line to

        <function name="the_function">
    

    It will correctly report the memory leak. However, I would rather not have to do this if possible. I'm using a very large library and the user-facing side of the API documentation does not specify if something is a macro, or an actual function (assumably to keep backwards compatibility with old code, etc). Any suggestions? Or am I out of luck? Thanks.

    Edit: I'm using 1.70 Win7

     

    Last edit: Justin Dailey 2015-09-22
  • Daniel Marjamäki

    I can see your problem.

    As you probably know.. the preprocessor just replaces the_macro with the the_function and there is no way to know what the original name was. So imho there is nothing we can do after the preprocessor.

    I assume the macro is in a header file. Do you get some problems if you remove the -I ?

     

    Last edit: Daniel Marjamäki 2015-09-23
  • Justin Dailey

    Justin Dailey - 2015-09-23

    Yes that macro is in a header file. If I remove the include for that directory, then CppCheck does not report as many errors, warnings, etc since there are alot of other normal macros and function declarations in those header files.

    Thanks for the help anyways.

     

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.