Uploaded image for project: 'Qbs ("Cubes")'
  1. Qbs ("Cubes")
  2. QBS-674

Operator == can not handle null pointers correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 1.3.1
    • 1.3.0
    • General
    • None
    • a3207a7293f0ee06d51146a6e98c3a3b1833ae54

      Operator == takes references and those can never be 0 according to the standard.

      So the code "if (!!&a != !!&b) return false;" (and similar), which was apparently meant to handle null referrences, is going to get optimized out.

      The introduction of null referrences by calling operator == on dereferenced pointers is actually undefined behavior.

      The clang compiler also warns about this issue:

      .../src/shared/qbs/src/lib/corelib/language/resolvedfilecontext.cpp:78: warning: reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true [-Wundefined-bool-conversion]
      if (!!&a != !!&b)
      ~ ^

        For Gerrit Dashboard: QBS-674
        # Subject Branch Project Status CR V

            kandeler Christian Kandeler
            hunger Tobias Hunger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes