STORAGE: don't use CreateFileMapping on a zero length file

Mike McCormack mike at codeweavers.com
Mon Jan 19 01:38:41 CST 2004


Hi All,

The following call fails on zero length files (in accordance with MSDN), 
so we have to avoid using it.

   CreateFileMapping( hfile,NULL,flProtect, 0, 0, NULL );

Mike


ChangeLog:
* don't use CreateFileMapping on a zero length file
-------------- next part --------------
Index: dlls/ole32/stg_bigblockfile.c
===================================================================
RCS file: /home/wine/wine/dlls/ole32/stg_bigblockfile.c,v
retrieving revision 1.11
diff -u -r1.11 stg_bigblockfile.c
--- dlls/ole32/stg_bigblockfile.c	9 Sep 2003 19:39:31 -0000	1.11
+++ dlls/ole32/stg_bigblockfile.c	19 Jan 2004 07:08:44 -0000
@@ -222,22 +222,27 @@
   if (This->hfile == INVALID_HANDLE_VALUE)
     return FALSE;
 
-  /* create the file mapping object
-   */
-  This->hfilemap = CreateFileMappingA(This->hfile,
-                                      NULL,
-                                      This->flProtect,
-                                      0, 0,
-                                      NULL);
+  This->filesize.s.LowPart = GetFileSize(This->hfile,
+					 &This->filesize.s.HighPart);
 
-  if (!This->hfilemap)
+  if( This->filesize.s.LowPart || This->filesize.s.HighPart )
   {
-    CloseHandle(This->hfile);
-    return FALSE;
-  }
+    /* create the file mapping object
+     */
+    This->hfilemap = CreateFileMappingA(This->hfile,
+                                        NULL,
+                                        This->flProtect,
+                                        0, 0,
+                                        NULL);
 
-  This->filesize.s.LowPart = GetFileSize(This->hfile,
-					 &This->filesize.s.HighPart);
+    if (!This->hfilemap)
+    {
+      CloseHandle(This->hfile);
+      return FALSE;
+    }
+  }
+  else
+    This->hfilemap = NULL;
 
   This->maplist = NULL;
 
@@ -420,7 +425,8 @@
     /*
      * close file-mapping object, must be done before call to SetEndFile
      */
-    CloseHandle(This->hfilemap);
+    if( This->hfilemap )
+      CloseHandle(This->hfilemap);
     This->hfilemap = 0;
 
     /*
@@ -661,6 +667,9 @@
     {
 	DWORD numBytesToMap;
 	DWORD desired_access;
+
+        if( !This->hfilemap )
+            return FALSE;
 
 	if (lowoffset + PAGE_SIZE > This->filesize.s.LowPart)
 	    numBytesToMap = This->filesize.s.LowPart - lowoffset;


More information about the wine-patches mailing list