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

QFile::size() may return incorrect file size

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.6.1, 4.6.2, 4.6.3, 4.7.0, 4.7.1, 4.8.0, 4.8.x, 5.0.0
    • Core: I/O, Documentation
    • None
    • windows and linux

    Description

      1. calling ->size() will call flush() implicitly. Should be documented. as well as calling flush() in ->read() and maybe in other places...
      but ->map() does not call ensureFlushed(). why ?

      2. after unsuccessfull flush(), QFile hang in intermediate state (lastWasWrite has been reset, but data was not actually written. )

      inline bool QFilePrivate::ensureFlushed() const
      {
          // This function ensures that the write buffer has been flushed (const
          // because certain const functions need to call it.
          if (lastWasWrite) {
              const_cast<QFilePrivate *>(this)->lastWasWrite = false;
              if (!const_cast<QFile *>(q_func())->flush())
                  return false;
          }
          return true;
      }
      

      3. At least bug in returning size as zero, beacuse:

      qint64 QFile::size() const
      {
          Q_D(const QFile);
          if (!d->ensureFlushed())
              return 0;
          d->cachedSize = fileEngine()->size();
          return d->cachedSize;
      }
      

      maybe more proper is to return -1 ? If yes, please fix documentation about negative return value.

      Attachments

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

        Activity

          People

            earthdomain Earth Domain (Inactive)
            socketpair@gmail.com Коренберг Марк
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes