Date: Sat, 2 Feb 2008 14:28:02 +1300
authorRyan C. Gordon <icculus@icculus.org>
Sat, 02 Feb 2008 02:32:48 +0000
changeset 924 fb5bc1b528c9
parent 923 dd40553428d0
child 926 0b5b2af3200d
Date: Sat, 2 Feb 2008 14:28:02 +1300 From: eH To: physfs@icculus.org Subject: [physfs] lzma.c msvc, etc. patch I came across a few bugs compiling PhysFS with msvc9 - I've created a patch which seems to fix them: SzFileReadImp / SzFileSeekImp: Problem: Can't preform arithmatic on 'void *' Fix: Cast 'object' to unsigned long LZMA_enumerateFiles: Problem: There is no error handling if the directory 'dname' doesn't exist Fix: Check the return value of 'lzma_find_file()' before using it LZMA_isDirectory: Problem: return (file->item->IsDirectory) is illegal if 'file' doesn't exist Fix: Make sure 'file' isn't null before returning
CHANGELOG.txt
archivers/lzma.c
--- a/CHANGELOG.txt	Wed Jan 23 05:14:15 2008 +0000
+++ b/CHANGELOG.txt	Sat Feb 02 02:32:48 2008 +0000
@@ -2,6 +2,7 @@
  * CHANGELOG.
  */
 
+02012008 - lzma fixes (thanks, eH!).
 01222008 - Upgraded lzma sdk, lzma.c improvements (thanks, Dennis!).
            Added zlib README, and updated LICENSE.txt.
 01212008 - Fixed HTTP header in physfshttpd.c. Fixed utf-8 to UCS-2 allocation
--- a/archivers/lzma.c	Wed Jan 23 05:14:15 2008 +0000
+++ b/archivers/lzma.c	Sat Feb 02 02:32:48 2008 +0000
@@ -130,7 +130,7 @@
 SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size,
                         size_t *processedSize)
 {
-    FileInputStream *s = (FileInputStream *)(object - offsetof(FileInputStream, inStream)); // HACK!
+    FileInputStream *s = (FileInputStream *)((unsigned long)object - offsetof(FileInputStream, inStream)); // HACK!
     size_t processedSizeLoc = __PHYSFS_platformRead(s->file, buffer, 1, size);
     if (processedSize != 0)
         *processedSize = processedSizeLoc;
@@ -145,7 +145,7 @@
  */
 SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
 {
-    FileInputStream *s = (FileInputStream *)(object - offsetof(FileInputStream, inStream)); // HACK!
+    FileInputStream *s = (FileInputStream *)((unsigned long)object - offsetof(FileInputStream, inStream)); // HACK!
     if (__PHYSFS_platformSeek(s->file, (PHYSFS_uint64) pos))
         return SZ_OK;
     return SZE_FAIL;
@@ -563,8 +563,18 @@
     size_t dlen = strlen(dname),
            dlen_inc = dlen + ((dlen > 0) ? 1 : 0);
     LZMAarchive *archive = (LZMAarchive *) opaque;
-    LZMAfile *file = (dlen ? lzma_find_file(archive, dname) + 1 : archive->files),
-             *lastFile = &archive->files[archive->db.Database.NumFiles];
+    LZMAfile *file = NULL,
+            *lastFile = &archive->files[archive->db.Database.NumFiles];
+        if (dlen)
+        {
+            file = lzma_find_file(archive, dname);
+            if (file != NULL) // if 'file' is NULL it should stay so, otherwise errors will not be handled
+                file += 1;
+        }
+        else
+        {
+            file = archive->files;
+        }
 
     BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, );
 
@@ -620,7 +630,7 @@
 
     *fileExists = (file != NULL);
 
-    return(file->item->IsDirectory);
+    return(file == NULL ? 0 : file->item->IsDirectory);
 } /* LZMA_isDirectory */