Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74476

QJSEngine::evaluate() incorrectly evaluates logic inside if statements.

    XMLWordPrintable

Details

    • c091f3f4b4889ac6be26e018c5e8b673adee7c47 (qt/qtdeclarative/5.12)

    Description

      "1<1" does not return the same value as "1<1?true:false".

      When comparing numeric literals X and Y, the operators <, >, <=, and >= seem to always give the right answer except for when X == Y and both are non-negative.

      These operators all behave correctly on their own (e.g. "1<1" returns false).
      However, inside a regular "if" statement or a ternary operator they
      behave as described above, evaluating incorrectly when comparing a number to
      itself (e.g. "if(1<1){true;}else{false;}" and "1<1?true:false" both return true).

      The following unit test demonstrates the bug. It passes in versions prior to 5.11.0 and fails in all versions since 5.11.0.  (Tested versions include 5.6.2, 5.7.0, 5.9.0, 5.10.0, 5.10.1, 5.11.0, 5.11.1, 5.12.1)

      void tst_QJSEngine::logicError()
      {
          QJSEngine engine;
          QJSValue value =
              engine.evaluate("( 0 < 0 ) ? 'WRONG ANSWER' : 'RIGHT ANSWER'");
          QVERIFY(!value.isError());
          QCOMPARE(value.toString(), "RIGHT ANSWER");
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            erikv Erik Verbruggen
            drbanyai Douglas Banyai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes