Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Bug in CByteArray::Serialize?

Posted on 2003-10-28
3
Medium Priority
?
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

609 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