Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why a warning on this line?



  • In this class method:

    QStringList clsScriptHelper::slstJSON(const void* cpJson
                                         ,const QJsonValue::Type cType
                                         ,QString strRef
                                         ,uint8_t uint8Level
                                         ,uint8_t* puint8MaxLength) {
        QStringList slstKeys, slstResult;
        const QJsonArray* cparyJSON;
        const QJsonObject* cpobjJSON;
        int intSize;
        if ( cType == QJsonValue::Array ) {
            cparyJSON = static_cast<const QJsonArray*>(cpJson);
            cpobjJSON = nullptr;
            intSize = cparyJSON->size();
        }
        if ( cType == QJsonValue::Object ) {
            cparyJSON = nullptr;
            cpobjJSON = static_cast<const QJsonObject*>(cpJson);
            slstKeys = cpobjJSON->keys();
            intSize = slstKeys.size();
        }
        if ( cparyJSON == nullptr && cpobjJSON == nullptr ) {
        //Invalid type, do nothing
            return slstResult;
        }
    

    On the line:

        if ( cparyJSON == nullptr && cpobjJSON == nullptr ) {
    

    There is a yellow background and message to the right:

    The left operand of '==' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
    

    What does mean? I can't see anything wrong with the code itself.


  • Lifetime Qt Champion

    @SPlatten said in Why a warning on this line?:

    const QJsonArray* cparyJSON;

    Because this pointer is not initialized and thus contains garbage (if none of the other if blocks is executed).
    You should always initialize pointers when you declare them.


  • Lifetime Qt Champion

    @SPlatten said in Why a warning on this line?:

    const QJsonArray* cparyJSON;

    Because this pointer is not initialized and thus contains garbage (if none of the other if blocks is executed).
    You should always initialize pointers when you declare them.



  • Thank you.



  • This post is deleted!

Log in to reply