Fixed crash on zero-byte read/write (thanks, Ensiform!).
authorRyan C. Gordon <icculus@icculus.org>
Wed, 11 Jul 2007 22:11:29 +0000
changeset 901 6dbb6a4e27a9
parent 899 ae19fe631c99
child 903 f5bad51e0f93
Fixed crash on zero-byte read/write (thanks, Ensiform!).
CHANGELOG.txt
physfs.c
--- a/CHANGELOG.txt	Sun May 27 14:34:29 2007 +0000
+++ b/CHANGELOG.txt	Wed Jul 11 22:11:29 2007 +0000
@@ -2,6 +2,7 @@
  * CHANGELOG.
  */
 
+07112007 - Fixed crash on zero-byte read/write (thanks, Ensiform!).
 05272007 - FIXME removal: Replaced a strncpy() with a memcpy().
 05112007 - Minor documentation correction.
 05052007 - Fixed zip archiver: could do bogus seek if a small, non-zip file
--- a/physfs.c	Sun May 27 14:34:29 2007 +0000
+++ b/physfs.c	Wed Jul 11 22:11:29 2007 +0000
@@ -1978,6 +1978,8 @@
     FileHandle *fh = (FileHandle *) handle;
 
     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)
         return(doBufferedRead(fh, buffer, objSize, objCount));
 
@@ -2011,6 +2013,8 @@
     FileHandle *fh = (FileHandle *) handle;
 
     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)
         return(doBufferedWrite(handle, buffer, objSize, objCount));