Solved

Bug in CByteArray::Serialize?

Posted on 2003-10-28
3
436 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now