Bug: VC7 MFC CByteArray::Serialize 
Author Message
 Bug: VC7 MFC CByteArray::Serialize

Hi MFC users

I found a bug in MFC's "array_b.cpp". The function CByteArray::Serialize serializes more bytes than needed. The last statement in the while loop is not correct and must be removed!
Has anybody an idea how to wrap around this problem? Serializing is critical, because we need to be compatible to our old versions. And in the serialised file the class "CByteArray" is mentioned, so that we cannot write a wrapper class.



Sat, 25 Sep 2004 22:50:05 GMT  
 Bug: VC7 MFC CByteArray::Serialize
Hi,

This issue has been notified before. It has a bug in the loading part of
the code. It has already been
logged and would be fixed in the next release. Thanks for pointing this out.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com



Tue, 28 Sep 2004 10:52:38 GMT  
 Bug: VC7 MFC CByteArray::Serialize

Quote:

> Hi MFC users

> I found a bug in MFC's "array b.cpp". The function CByteArray::Serialize
> serializes more bytes than needed. The last statement in the while loop
> is not correct and must be removed!
> Has anybody an idea how to wrap around this problem? Serializing is
> critical, because we need to be compatible to our old versions. And in
> the serialised file the class "CByteArray" is mentioned, so that we
> cannot write a wrapper class.

> --

Hi try.

1. Try create your own class inherited from CByteArray and replace
function Serialize().
You must remove line with code :

this is a bug    >>       ar.Read(pbData, nBytesToRead); <<

void CByteArray::Serialize(CArchive& ar)

- Show quoted text -

Quote:
>{
>    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;
>this is a bug    >>   ar.Read(pbData, nBytesToRead); <<
>            }
>    }
>}

Then you must redirect all your CByteArray classes to CByteArrayMy
classes.
It's very laborious for large projects. I did it for my project with
about 1000 classes.

2. Or try recompile all MFC library with repair of CByteArray. But
this is a risk.

3. Or wait for new VC.Net release :-)

Milan



Sun, 03 Oct 2004 15:00:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Bug in CByteArray::Serialize

2. CByteArray Serialize code changed in MFC 7.0

3. Serializing Dynamic Data structures in VC7:MFC

4. Serializing Dynamic Data structures in VC7:MFC

5. Serializing Dynamic Data structures in VC7:MFC

6. CByteArray serialize assert

7. Found bug in vc7 mfc code...

8. BUG with VC7 RC1 with an MFC AppWizard generated CEditView project

9. possible bug in VC6, VC7, VC7.1

10. Possible bug in vc7.0 (and vc7.1)

11. VC7: BUG in IMPLEMENT_SERIAL (MFC)

12. my bug or VC7 bug ?

 

 
Powered by phpBB® Forum Software