Don't use CreateFileMapping on a zero length file.

This commit is contained in:
Mike McCormack 2004-01-19 21:44:02 +00:00 committed by Alexandre Julliard
parent 4cd80a3637
commit 2cee7ac6d9
1 changed files with 24 additions and 15 deletions

View File

@ -222,23 +222,28 @@ static BOOL BIGBLOCKFILE_FileInit(LPBIGBLOCKFILE This, HANDLE hFile)
if (This->hfile == INVALID_HANDLE_VALUE)
return FALSE;
/* create the file mapping object
*/
This->hfilemap = CreateFileMappingA(This->hfile,
NULL,
This->flProtect,
0, 0,
NULL);
if (!This->hfilemap)
{
CloseHandle(This->hfile);
return FALSE;
}
This->filesize.s.LowPart = GetFileSize(This->hfile,
&This->filesize.s.HighPart);
if( This->filesize.s.LowPart || This->filesize.s.HighPart )
{
/* create the file mapping object
*/
This->hfilemap = CreateFileMappingA(This->hfile,
NULL,
This->flProtect,
0, 0,
NULL);
if (!This->hfilemap)
{
CloseHandle(This->hfile);
return FALSE;
}
}
else
This->hfilemap = NULL;
This->maplist = NULL;
TRACE("file len %lu\n", This->filesize.s.LowPart);
@ -420,7 +425,8 @@ void BIGBLOCKFILE_SetSize(LPBIGBLOCKFILE This, ULARGE_INTEGER newSize)
/*
* close file-mapping object, must be done before call to SetEndFile
*/
CloseHandle(This->hfilemap);
if( This->hfilemap )
CloseHandle(This->hfilemap);
This->hfilemap = 0;
/*
@ -662,6 +668,9 @@ static BOOL BIGBLOCKFILE_MapPage(LPBIGBLOCKFILE This, MappedPage *page)
DWORD numBytesToMap;
DWORD desired_access;
if( !This->hfilemap )
return FALSE;
if (lowoffset + PAGE_SIZE > This->filesize.s.LowPart)
numBytesToMap = This->filesize.s.LowPart - lowoffset;
else