r928 - in trunk: . archivers

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Feb 1 21:32:48 EST 2008


Author: icculus
Date: 2008-02-01 21:32:48 -0500 (Fri, 01 Feb 2008)
New Revision: 928

Modified:
   trunk/CHANGELOG.txt
   trunk/archivers/lzma.c
Log:
Date: Sat, 2 Feb 2008 14:28:02 +1300
From: eH
To: physfs at 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



Modified: trunk/CHANGELOG.txt
===================================================================
--- trunk/CHANGELOG.txt	2008-01-23 05:14:15 UTC (rev 927)
+++ trunk/CHANGELOG.txt	2008-02-02 02:32:48 UTC (rev 928)
@@ -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

Modified: trunk/archivers/lzma.c
===================================================================
--- trunk/archivers/lzma.c	2008-01-23 05:14:15 UTC (rev 927)
+++ trunk/archivers/lzma.c	2008-02-02 02:32:48 UTC (rev 928)
@@ -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 */
 
 




More information about the physfs-commits mailing list