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

If QFile is empty, readAll() crashes with std::bad_alloc

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.1.1
    • 5.0.2, 5.1.0 Beta 1
    • Core: I/O
    • None
    • Windows 7. In linux this works fine
    • 01b6eea4157a7a3d45e55e3ada9786aaaccb99fb

    Description

      Run the following code. readAll() crashes with std::bad_alloc. The file size of QFile is big positive number when it should be 0.

      #include <QApplication>
      #include <QtCore/QFile>
      #include <QtCore/QDebug>
      
      int main(int argc, char *argv[])
      {
          for(;;)
          {
              int size = rand()%128;
              qDebug()<<size;
      
              char* data = (char*)malloc(size);
      
      
              for(int i=0;i<size;i++)
                  data[i] = 'j';
              free(data);
      
              QFile f;
              qDebug()<<"read list "<<QString::number((int)f.size());
      
              f.readAll();
          }
      
          return 0;
      }
      

      Attachments

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

        Activity

          People

            andysh Andy Shaw
            qtcomsupport Qt Support
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes