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

UB on QMap::const_iterator compare when d == nullptr

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.2.6, 6.4.1
    • None

    Description

      As detected by Lyx guys (https://www.lyx.org/trac/ticket/12215), we're comparing singular (= default-constructed) std:map const_iterator'ss, which is UB. We seem to be creating them when {{d == nullptr}:

      const_iterator begin() const noexcept
      { return d ? const_iterator(d->m.begin()) :
         /* here: */ const_iterator() ; }
      

      It's unclear how to solve the issue. One way would be to wrap the std::map::const_iterator in std:aligned_union and placing a marker (0b1 in the LSB, which should never be set in a pointer to a node) for the default-construted state. Basically a compact form of optional<>. How compatible that is with libstdc++ debug STL builds remains to be seen.

      Attachments

        Activity

          People

            peppe Giuseppe D'Angelo
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: