Explorar el Código

Fixed crash on zero-byte read/write (thanks, Ensiform!).

Ryan C. Gordon hace 18 años
padre
commit
c5ee3d965c
Se han modificado 2 ficheros con 5 adiciones y 0 borrados
  1. 1 0
      CHANGELOG.txt
  2. 4 0
      physfs.c

+ 1 - 0
CHANGELOG.txt

@@ -2,6 +2,7 @@
  * CHANGELOG.
  * CHANGELOG.
  */
  */
 
 
+07112007 - Fixed crash on zero-byte read/write (thanks, Ensiform!).
 05272007 - FIXME removal: Replaced a strncpy() with a memcpy().
 05272007 - FIXME removal: Replaced a strncpy() with a memcpy().
 05112007 - Minor documentation correction.
 05112007 - Minor documentation correction.
 05052007 - Fixed zip archiver: could do bogus seek if a small, non-zip file
 05052007 - Fixed zip archiver: could do bogus seek if a small, non-zip file

+ 4 - 0
physfs.c

@@ -1978,6 +1978,8 @@ PHYSFS_sint64 PHYSFS_read(PHYSFS_File *handle, void *buffer,
     FileHandle *fh = (FileHandle *) handle;
     FileHandle *fh = (FileHandle *) handle;
 
 
     BAIL_IF_MACRO(!fh->forReading, ERR_FILE_ALREADY_OPEN_W, -1);
     BAIL_IF_MACRO(!fh->forReading, ERR_FILE_ALREADY_OPEN_W, -1);
+    BAIL_IF_MACRO(objSize == 0, NULL, 0);
+    BAIL_IF_MACRO(objCount == 0, NULL, 0);
     if (fh->buffer != NULL)
     if (fh->buffer != NULL)
         return(doBufferedRead(fh, buffer, objSize, objCount));
         return(doBufferedRead(fh, buffer, objSize, objCount));
 
 
@@ -2011,6 +2013,8 @@ PHYSFS_sint64 PHYSFS_write(PHYSFS_File *handle, const void *buffer,
     FileHandle *fh = (FileHandle *) handle;
     FileHandle *fh = (FileHandle *) handle;
 
 
     BAIL_IF_MACRO(fh->forReading, ERR_FILE_ALREADY_OPEN_R, -1);
     BAIL_IF_MACRO(fh->forReading, ERR_FILE_ALREADY_OPEN_R, -1);
+    BAIL_IF_MACRO(objSize == 0, NULL, 0);
+    BAIL_IF_MACRO(objCount == 0, NULL, 0);
     if (fh->buffer != NULL)
     if (fh->buffer != NULL)
         return(doBufferedWrite(handle, buffer, objSize, objCount));
         return(doBufferedWrite(handle, buffer, objSize, objCount));