Skip to content

Commit

Permalink
Date: Sat, 2 Feb 2008 14:28:02 +1300
Browse files Browse the repository at this point in the history
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
  • Loading branch information
icculus committed Feb 2, 2008
1 parent f7f6c0e commit ac277da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions archivers/lzma.c
Expand Up @@ -130,7 +130,7 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxReqSize,
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;
Expand All @@ -145,7 +145,7 @@ SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size,
*/
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;
Expand Down Expand Up @@ -563,8 +563,18 @@ static void LZMA_enumerateFiles(dvoid *opaque, const char *dname,
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, );

Expand Down Expand Up @@ -620,7 +630,7 @@ static int LZMA_isDirectory(dvoid *opaque, const char *name, int *fileExists)

*fileExists = (file != NULL);

return(file->item->IsDirectory);
return(file == NULL ? 0 : file->item->IsDirectory);
} /* LZMA_isDirectory */


Expand Down

0 comments on commit ac277da

Please sign in to comment.