Menu

cfg file & resource - why is return parameter required ?

2016-03-22
2016-03-22
  • William Reich

    William Reich - 2016-03-22

    Hi - I am new to cppchecker. It seems like a good idea. Thanks for creating it.

    I am trying to create a configuration file that will catch the failure to release a lock.

    The tool seems to believe that a 'resource' function call must have a return parameter.
    However, I am dealing with simply getReadLock() and getWriteLock() and unLock() , all returning void.
    This C++ objects afterall...

    My simply code test case is this:

    int foo()
    {
    char a[10] ;
    a[10] = 0 ;
    getReadLock() ;
    unLock() ;
    getWriteLock() ;
    unLock() ;
    return 0 ;
    }

    int main()
    {
    return foo() ;
    }

    -- end code

    My output from the tool ( 1.72 ) is this:

    [q.c:7]: (style) Variable 'a' is assigned a value that is never used.
    [q.c:7]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.
    [q.c:9]: (error) Return value of allocation function getReadLock is not used.
    [q.c:11]: (error) Return value of allocation function getWriteLock is not used.

    My cfg file is this:
    <?xml version="1.0"?>
    <def>
    <function name="dostuff">
    <leak-ignore/>
    <arg nr="1"/>
    <arg nr="2"/>
    </function>
    <resource>
    <alloc>getReadLock</alloc>
    <dealloc>releaseLock</dealloc>
    <dealloc>unLock</dealloc>
    </resource>
    <resource>
    <alloc>getWriteLock</alloc>
    <dealloc>releaseLock</dealloc>
    <dealloc>unLock</dealloc>
    </resource>
    </def>

    My command line is this:
    /u/reich/dsc/cppcheck --enable=all --platform=unix64 --std=c99 \ --std=posix --std=c++03 \ --library=/u/reich/dsc/cfg/posix.cfg \ --library=/u/reich/dsc/cfg/std.cfg \ --library=/u/reich/dsc/dsc.cfg \ --language=c++ \ -I/u/reich/dsc/other_include \ -I/usr/include \ -D_REENTRANT -Dx86_64 -Dx86_64 \ --verbose \ -Dcplusplus -Dlinux -DLINUX -DGNUC -DSTDC__ -U_ADCSIM_ $1 2> $1.xml

    ( sorry, I did not see a way to attach a tarball of these items )

    I'm looking for the tool to
    a) not report this error
    b) report a 'resource leak' when I forget to provide the unlock() in the code.

    Please advise. Thanks

     
  • William Reich

    William Reich - 2016-03-22

    hmm... the 'attach' button seems to appear on replies to posts, so here is the tarball...

     

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.