Menu

knownConditionTrueFalse false positive

2024-04-29
2024-04-29
  • Steve Albright

    Steve Albright - 2024-04-29

    2.14

    knownConditionTrueFalse - Condition 'buffer.isEmpty()' is always false

    void Example(const QString& buffer, bool dd)
    {
    if(buffer.isEmpty() || (dd && buffer.isEmpty()))
    {
    // do something
    }
    }

    Extracting isEmpty into a Boolean is a workaround. Originally, I took the second isEmpty() out but that is a logic error.

     
  • CHR

    CHR - 2024-04-29

    That's a true positive. The second isEmpty() is always false and indicated as such:

    foo.cpp:3:45: style: Condition 'buffer.isEmpty()' is always false [knownConditionTrueFalse]
    if(buffer.isEmpty() || (dd && buffer.isEmpty()))
                                                ^
    foo.cpp:3:18: note: Assuming that condition 'buffer.isEmpty()' is not redundant
    if(buffer.isEmpty() || (dd && buffer.isEmpty()))
                     ^
    foo.cpp:3:45: note: Condition 'buffer.isEmpty()' is always false
    if(buffer.isEmpty() || (dd && buffer.isEmpty()))
                                                ^
    
     

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.