Menu

Need help on few of the cppcheck rules

kpk
2020-11-23
2020-11-26
  • kpk

    kpk - 2020-11-23

    cppcheck 2.0
    1. incorrect locking with mutex - Called std::mutex lock() and unlock() is not invoked. The violation js not detected. std::mutex is supported?
    2. Call of pure virtual function in constructor/destructor - is not working .
    3. Not taking the address to allocated memory is not reported for statement like new int() ; but reports issue when malloc is used
    4. Dangerous usage of strncat() - not reported issue when source and destination buffers overlap.
    5. Partial string write that leads to buffer that is not zero terminated -- not reports issue when memcpy is used.

     
  • Daniel Marjamäki

    Thanks!

    could you please provide some small test cases. then I will open tickets..

    if you want you could create some kind of test suite with various test cases.

    If I test out Cppcheck then it will find many bugs I can imagine. It is not optimal when the tester and developer are the same person. So I think a test suite written by you would have interesting variations that I would miss.

     

    Last edit: Daniel Marjamäki 2020-11-24
  • kpk

    kpk - 2020-11-26

    Thanks for the reply.
    I have below queries. incorrect locking with mutex is not detected for below code.
    int i = 0;
    std::mutex m;
    void test()
    {
    m.lock();
    i++;
    return;
    }
    - Call of pure virtual function in constructor/destructor - Is this enabled in 2.0. There was a discussion in tbe forum that issue in 1.9

     

    Last edit: kpk 2020-11-26
  • Daniel Marjamäki

    We do not warn about that. You might unlock the mutex in the function that calls test. Imho it would be a more robust coding style to use a scope lock.

    We have some checks for std::mutex as you can see in the teststl.cpp file. You can search for "std::mutex" here: https://github.com/danmar/cppcheck/blob/main/test/teststl.cpp

    Call of pure virtual function in constructor/destructor - Is this enabled in 2.0. There was a discussion in tbe forum that issue in 1.9

    which forum?

     

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.