FIX: CFile::ReadHuge May Return Incorrect ValueLast reviewed: September 18, 1997Article ID: Q109849 |
1.00
WINDOWS
kbprg kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSThe member function CFile::ReadHuge may return an incorrect value.
CAUSEA miscalculation exists in the CFile::ReadHuge() function located in FILEX.CPP. FILEX.CPP may be found in the \MSVC\MFC\SRC directory.
RESOLUTIONTo correct the problem, replace the code for CFile::ReadHuge() with the code below. You can modify the Microsoft Foundation Class (MFC) Library sources or you could make the function a new function of some CFile-derived class.
Sample CodeDWORD CFile::ReadHuge(void FAR* lpBuffer, DWORD dwCount) { ASSERT_VALID(this); DWORD dwToRead = dwCount; while (dwToRead > 0) { UINT nRead = _AfxCalcSize(dwToRead, lpBuffer); UINT nActuallyRead; if ((nActuallyRead = Read(lpBuffer, nRead)) < nRead) return ((dwCount - dwToRead) + nActuallyRead); ASSERT(nActuallyRead == nRead); dwToRead -= nRead; lpBuffer = ((BYTE _huge*)lpBuffer) + nRead; } return dwCount;}
STATUSMicrosoft has confirmed this to be a bug in the products listed at the beginning of this article. This problem was corrected in MFC 2.5, included with Visual C++ for Windows, version 1.5.
MORE INFORMATIONThe code below illustrates the problem. When the program is executed, the output line will be:
Read returns 0, ReadHuge returns 512Both reads should return zero for a zero-length file.
Sample Code
// compile options required: none void Test() { CFile file; CFileException exception; char * buffer[1024]; UINT read1; DWORD read2; ASSERT(file.Open( "blank.txt", CFile::modeReadWrite | CFile::typeBinary | CFile::modeCreate, &exception )); read1 = file.Read( buffer, 512 ); file.Seek( 0, CFile::begin ); read2 = file.ReadHuge( buffer, 512 ); TRACE( "Read returns %d, ReadHuge returns %ld\n", read1, read2 ); file.Close(); } |
Additional reference words: 1.00 2.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |