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

QApplication::setInputContext does not guard against self-assignment

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.7.0
    • 4.6.1
    • Core: Event loop
    • None
    • a32c96e753c2f5a123e518a92762ec9c9ff3b0b7

    Description

      The current implementation of QApplication::setInputContext is wrong:

      void QApplication::setInputContext(QInputContext *inputContext)
      {
          Q_D(QApplication);
          Q_UNUSED(d);// only static members being used.
          if (!inputContext) {
              qWarning("QApplication::setInputContext: called with 0 input context");
              return;
          }
          delete d->inputContext;
          d->inputContext = inputContext;
      }
      

      If d->inputContext already pointed to the same instance as inputContext, then it'll assign a dangling pointer to d->inputContext, which can easily crash the application.

      So what's wrong:

      • No guard against self-assignment,
      • After calling delete, d->inputContext should be set to 0 (or, d->inputContext should be wrapped in a QPointer),
      • Since QInputContext can be parented, it is questionable whether this setter should delete anything at all - The documentation does not mention this behaviour (to "replace" an object is not necessarily the same as destroying it).

      (selected "text handling" since QInputContext is a text input helper)

      Attachments

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

        Activity

          People

            dzyubenk Denis Dzyubenko (Inactive)
            mikhas Michael Hasselmann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes