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

Add assert to qAllocMore() function in QByteArray.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 4.8.5
    • None

    Description

      The case is derived from QTBUG-32999 case.

      Qt 5 has assert inside assert to qAllocMore() function in QByteArray.

      int qAllocMore(int alloc, int extra)
      {
          Q_ASSERT(alloc >= 0 && extra >= 0);
          Q_ASSERT_X(alloc < (1 << 30) - extra, "qAllocMore", "Requested size is too large!");
      
          unsigned nalloc = alloc + extra;
      
          // Round up to next power of 2
      
          // Assuming container is growing, always overshoot
          //--nalloc;
      
          nalloc |= nalloc >> 1;
          nalloc |= nalloc >> 2;
          nalloc |= nalloc >> 4;
          nalloc |= nalloc >> 8;
          nalloc |= nalloc >> 16;
          ++nalloc;
      
          Q_ASSERT(nalloc > unsigned(alloc + extra));
      
          return nalloc - extra;
      }
      

      But, the assert is missing for Qt 4 environment.

      int qAllocMore(int alloc, int extra)
      {
          if (alloc == 0 && extra == 0)
              return 0;
          const int page = 1 << 12;
          int nalloc;
          alloc += extra;
          if (alloc < 1<<6) {
              nalloc = (1<<3) + ((alloc >>3) << 3);
          } else  {
              // don't do anything if the loop will overflow signed int.
              if (alloc >= INT_MAX/2)
                  return INT_MAX;
              nalloc = (alloc < page) ? 1 << 3 : page;
              while (nalloc < alloc) {
                  if (nalloc <= 0)
                      return INT_MAX;
                  nalloc *= 2;
              }
          }
          return nalloc - extra;
      }
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            leonlee Leonard Lee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes