Menu

False positive: knownConditionTrueFalse [v2.2]

CHR
2020-10-05
2021-01-23
  • CHR

    CHR - 2020-10-05

    This cropped up in v2.2. There is an early return if both containers are empty, but OldFormat can still be false.

    #include <string>
    #include <vector>
    
    bool foo(bool b) { return !b; }
    
    bool thud(const std::vector<std::wstring>& Arr, const std::wstring& Str)
    {
      if (Arr.empty() && Str.empty())
        return false;
    
      bool OldFormat = Arr.empty() && !Str.empty(); // style: Condition 'OldFormat' is always true [knownConditionTrueFalse]
      if (OldFormat)
        return foo(OldFormat); // no warning without this call (e.g. just return true;)
      return false;
    }
    
    int main() {
        std::vector<std::wstring> Arr;
        std::wstring Str;
    
        return thud(Arr, Str) ? 1 : 0;
    }
    
     
  • CHR

    CHR - 2021-01-22

    This is still reported in 2.3, but I think I have seen a similar ticket somewhere.

     
  • Daniel Marjamäki

    This is still reported in 2.3, but I think I have seen a similar ticket somewhere.

    oops sorry no response. let me know if you find the ticket or not..

     
  • CHR

    CHR - 2021-01-23

    Probably I remembered this one: https://trac.cppcheck.net/ticket/10088
    But that's not quite the same issue, so a new ticket might be in order.

     
  • Daniel Marjamäki

     

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.