Menu

knownConditionTrueFalse False Positive

2024-05-24
2024-05-24
  • Steve Albright

    Steve Albright - 2024-05-24

    I think it might be considering the isNull check and because not null it thinks it has content but they are two different things.

    style: knownConditionTrueFalse - Condition '!sourceFilePath.isEmpty()' is always true

    bool Example(const QString& sourceFilePath, const QUuid& rowMapErid)
    {
       bool success = false;
       if(not sourceFilePath.isNull() and not sourceFilePath.isEmpty() and not rowMapErid.isNull())
       {
          success = CopyFile(sourceFilePath, rowMapErid);
       }
    
       return success;
    }
    
     
  • CHR

    CHR - 2024-05-24

    https://doc.qt.io/qt-6/qstring.html#isNull doesn't explain the difference, except mentioning "historical reasons". So why have both checks?

     
    • Steve Albright

      Steve Albright - 2024-05-24

      This is the key difference

      QString("").isNull(); // returns false

      QString().isEmpty(); // returns true
      QString("").isEmpty(); // returns true

       
  • CHR

    CHR - 2024-05-24
     

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.