Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why a warning on this line?
Forum Updated to NodeBB v4.3 + New Features

Why a warning on this line?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      6
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        Thank you.

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @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.

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved