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

Crash in qwindows11style with null widget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 6.7.1, 6.8.0 FF
    • 6.7.0 RC2
    • Widgets: Styles
    • None
    • Windows
    • a35f57d42 (dev), 8b193397f (6.7)

    Description

      qwindows11style crashes when drawing progress bar if qobject_cast fails.

      I haven't debugged yet (end of my work day right now), but wanted to report in case the fix is obvious for you (should it just check the result of the qobject_cast?).

      Here's the code:

          case QStyle::CE_ProgressBarGroove:{
              if (const QStyleOptionProgressBar* progbaropt = qstyleoption_cast<const QStyleOptionProgressBar*>(option)) {
                  const QProgressBar bar = qobject_cast<const QProgressBar*>(widget);*
                  QRectF rect = subElementRect(SE_ProgressBarContents, progbaropt, widget);
                  QPointF center = rect.center();
                  if (bar->orientation() & Qt::Horizontal)

      {                 rect.setHeight(1);                 rect.moveTop(center.y());             }

      else

      {                 rect.setWidth(1);                 rect.moveLeft(center.x());             }

      (from qwindows11style.cpp)

      If widget isn't a QProgressBar* then the cast fails and a crash results.

      Update: initial value of widget is nullptr (from initiating call of QStyle::drawControl using default value for widget parameter), rather than being the wrong type. In any case, adding a null check for "bar" will avoid the crash.

       

       

      Attachments

        1. image-2024-03-28-10-52-22-726.png
          21 kB
          Michael Partridge
        2. image-2024-03-28-10-55-02-327.png
          8 kB
          Michael Partridge
        3. styles.zip
          3 kB
          Michael Partridge
        For Gerrit Dashboard: QTBUG-123791
        # Subject Branch Project Status CR V

        Activity

          People

            tpochep Timur Pocheptsov
            michael.partridge Michael Partridge
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes