Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QDataStream usage
Forum Updated to NodeBB v4.3 + New Features

QDataStream usage

Scheduled Pinned Locked Moved Qt WebKit
6 Posts 4 Posters 6.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lonial
    wrote on 28 Jul 2010, 04:17 last edited by
    #1

    Hi,

    I have doubt regrading usage of QDataStream::readRawData method. I am not sure that whether QDataStream will append ‘\0’ at the end of messageData string(see below code). I have checked QDataStream::readbytes implementation, it does append the ‘\0’ character at the end. Please confirm whether QDataStream::readRawData will append ‘\0’ at the end of string or not. Please also provide comment for below usage of QDataStream.

    Code snippet:

    @
    QDataStream streamToDeSerialize(&aSerializedData,QIODevice::ReadOnly);
    streamToDeSerialize>>mSessionId;
    streamToDeSerialize>>mAsyncRequestId;
    streamToDeSerialize>>mMessageType;
    streamToDeSerialize>>mMessageDataLength;
    char *messageData = new char[mMessageDataLength];
    streamToDeSerialize.readRawData(messageData,mMessageDataLength);
    @

    Thanks,
    Sumit Lonial

    edit: Code highlighting added / Denis Kormalev

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jobor
      wrote on 3 Aug 2010, 20:50 last edited by
      #2

      I hereby confirm that QDataStream::readRawData does not append \0.

      I also provide a comment for your usage of QDataStream. You probably want to do something with the return value of QDataStream::readRawData. Maybe something like:

      @
      int bytesRead = streamToDeSerialize.readRawData(messageData,mMessageDataLength);
      messageData[bytesRead] = 0;
      @

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lonial
        wrote on 4 Aug 2010, 05:22 last edited by
        #3

        Thanks for replying

        I am having doubt over usage, Here is complete usage:

            profileDataStream>>mMarketingDataLength;
            char *messageData = new char[mMarketingDataLength];
            profileDataStream.readRawData(messageData,mMarketingDataLength);
            data = QByteArray(messageData,mMarketingDataLength);
            mMarketingInfo = new MarketingConsentInfo( data );
            delete[] messageData;
        

        We are reading stream data from into c style string using readRawData. Then copying this c style string into QByteArray , QByteArray uses memcpy and add '\0' character at last position of array. This can lead to over writing of valid last character of stream with null character since we are not allocating space for it. I think we should allocate extra space for null character in this usage.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lonial
          wrote on 4 Aug 2010, 05:50 last edited by
          #4

          Resending as formatting was not good.

          Thanks for replying

          I am having doubt over usage, Here is complete usage:

          profileDataStream>>mMarketingDataLength;
          char *messageData = new char[mMarketingDataLength];
          profileDataStream.readRawData(messageData,mMarketingDataLength);
          data = QByteArray(messageData,mMarketingDataLength);
          mMarketingInfo = new MarketingConsentInfo( data );
          delete[] messageData;

          We are reading stream data from into c style string using readRawData. Then copying this c style string into QByteArray , QByteArray uses memcpy and add ’\0’ character at last position of array. This can lead to over writing of valid last character of stream with null character since we are not allocating space for it. I think we should allocate extra space for null character in this usage.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on 4 Aug 2010, 07:55 last edited by
            #5

            lonial, please use @ marks for code snippets.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Smar
              wrote on 4 Aug 2010, 16:19 last edited by
              #6

              [quote author="jobor" date="1280868636"]I hereby confirm that QDataStream::readRawData does not append \0.
              [/quote]

              This might be good to add to the documentation, it is not really clear about that part. Though it can be guessed and/or tested, it just sounds silly... :)

              1 Reply Last reply
              0

              4/6

              4 Aug 2010, 05:50

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved