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

MSVC: warning C4723: potential divide by 0 in Qt Gui

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 6.1.1, 6.2.0 Alpha
    • 6.2
    • GUI: Painting
    • None
    • Windows
    • 16a1ba69a682fbe7855682448ac0340574a67035 (qt/qtbase/dev) de1e66cd8bd957778c61015f53131781d32865d0 (qt/qtbase/6.1)

    Description

      cl version v16.9.4 warns about C4723 in qpixmap.cpp, qimage.cpp:

      C:\dev\qt\dev\src\qtbase\src\gui\image\qpixmap.cpp(516) : warning C4723: potential divide by 0
      C:\dev\qt\dev\src\qtbase\src\gui\image\qimage.cpp(1311) : warning C4723: potential divide by 0
      

      The lines in question look fairly standard though, and don't use divisions?

          return data ? data->height() : 0;
      
          return d ? d->height : 0;
      

      Anyhow, the warning is only at Release build, and most probably due to some optimizations MSVC does there. One can trace it to:

      QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const
      {
          if (isNull()) {
              qWarning("QPixmap::scaleHeight: Pixmap is a null pixmap");
              return copy();
          }
          if (h <= 0)
              return QPixmap();
      
          Q_TRACE_SCOPE(QPixmap_scaledToHeight, h, mode);
      
          qreal factor = (qreal) h / height();
          QTransform wm = QTransform::fromScale(factor, factor);
          return transformed(wm, mode);
      }
      

      One can see that there's a potential problem if height() == 0.

      Attachments

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

        Activity

          People

            vgt Eirik Aavitsland
            kkohne Kai Köhne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes