Solved

Bug in CByteArray::Serialize?

Posted on 2003-10-28
3
439 Views
Last Modified: 2013-11-20
Is there a bug in CByteArray::Serialize in Visual C++ .NET or have I misunderstood something?

It seems like when reading there is one ar.Read(pbData, nBytesToRead); to much. What can I do to correct this. Is it possible to recompile the C:\Program Files\Microsoft Visual Studio .NET\VC7\atlmfc\src\mfc\ array_b.cpp file?


// In Visual C++ 6.0 it works fine
void CByteArray::Serialize(CArchive& ar)
{
      ASSERT_VALID(this);

      CObject::Serialize(ar);

      if (ar.IsStoring())
      {
            ar.WriteCount(m_nSize);
            ar.Write(m_pData, m_nSize * sizeof(BYTE));
      }
      else
      {
            DWORD nOldSize = ar.ReadCount();
            SetSize(nOldSize);
            ar.Read(m_pData, m_nSize * sizeof(BYTE));
      }
}

// In Visual C++ .NET bug?
void CByteArray::Serialize(CArchive& ar)
{
      UINT_PTR nBytesLeft;
      UINT nBytesToWrite;
      UINT nBytesToRead;
      LPBYTE pbData;

      ASSERT_VALID(this);

      CObject::Serialize(ar);

      if (ar.IsStoring())
      {
            ar.WriteCount(m_nSize);
            nBytesLeft = m_nSize*sizeof(BYTE);
            pbData = m_pData;
            while(nBytesLeft > 0)
            {
                  nBytesToWrite = UINT(min(nBytesLeft, INT_MAX));
                  ar.Write(pbData, nBytesToWrite);
                  pbData += nBytesToWrite;
                  nBytesLeft -= nBytesToWrite;
            }
      }
      else
      {
            DWORD_PTR nOldSize = ar.ReadCount();
            SetSize(nOldSize);
            nBytesLeft = m_nSize*sizeof(BYTE);
            pbData = m_pData;
            while(nBytesLeft > 0)
            {
                  nBytesToRead = UINT(min(nBytesLeft, INT_MAX));
                  ar.Read(pbData, nBytesToRead);
                  pbData += nBytesToRead;
                  nBytesLeft -= nBytesToRead;
                  ar.Read(pbData, nBytesToRead); ////////////////////////////////////////////////////////Should be removed?
            }
      }
}
0
Comment
Question by:P1R
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9632838
Serialize is virtual function, you can derive your own class from CByteArray and overwrite the Serialize function. You can test by this way your correction to Serialize function.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 100 total points
ID: 9632844
0
 

Author Comment

by:P1R
ID: 9633333
Thanks AlexFM. I didn't expect to be the first to find this bug... The workaround works fine. It's nice to know that (for once?) it is Microsoft and not I that have made a mistake:-)
 
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
if loop in java 3 160
pre4 challenge 19 110
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 454
how to use laptop or pad camera in vb.net windows application 2 103
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question