Menu

False Positive. Suspicious condition. The result of find() is an iterator, but it is not properly checked.

2020-03-05
2020-03-10
  • Steffen Brauer

    Steffen Brauer - 2020-03-05
    #include <set>
    int main()
    {
            std::set<int> s;
            if (const auto it = s.find(1); it != s.end()) {}
            return 0;
    }
    

    This generates a warning with cppcheck 1.88:

    ~ $ cppcheck --enable=all cppcheck.cpp
    Checking cppcheck.cpp ...
    [cppcheck.cpp:5]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.

     
  • versat

    versat - 2020-03-10

    Thanks for reporting the issue.
    It looks like there is already a ticket for such issues: https://trac.cppcheck.net/ticket/9486
    I will add your code as another example for the false positive issue.

     
    • versat

      versat - 2020-03-10

      There is also another ticket which is already fixed: https://trac.cppcheck.net/ticket/9630
      I closed ticket 9486 as a duplicate one.
      That is why I can reproduce the issue with Cppcheck 1.90 but not with the latest development code.
      So with the next release (I guess 2.00) the issue is fixed.

       

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.