From DONOTREPLY at icculus.org Fri Feb 1 21:32:48 2008 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 1 Feb 2008 21:32:48 -0500 Subject: r928 - in trunk: . archivers Message-ID: <20080202023248.20990.qmail@icculus.org> 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 */ From DONOTREPLY at icculus.org Wed Feb 13 00:48:57 2008 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 13 Feb 2008 00:48:57 -0500 Subject: r929 - branches/stable-1.0 branches/stable-1.0/platform trunk trunk/platform Message-ID: <20080213054857.2933.qmail@icculus.org> Author: icculus Date: 2008-02-13 00:48:57 -0500 (Wed, 13 Feb 2008) New Revision: 929 Modified: branches/stable-1.0/CHANGELOG branches/stable-1.0/platform/win32.c trunk/CHANGELOG.txt trunk/platform/windows.c Log: Minor Windows fix (thanks, fydo!). Modified: branches/stable-1.0/CHANGELOG =================================================================== --- branches/stable-1.0/CHANGELOG 2008-02-02 02:32:48 UTC (rev 928) +++ branches/stable-1.0/CHANGELOG 2008-02-13 05:48:57 UTC (rev 929) @@ -4,6 +4,7 @@ -- stuff in the stable-1.0 branch, backported from 2.0.0 dev branch, etc --- +02132008 - Minor Windows fix (thanks, fydo!). 01222008 - Added zlib README, and updated LICENSE.txt. 01212008 - Fixed HTTP header in physfshttpd.c. 12112007 - Fixed incorrect directory test in Windows code (thanks, Buginator!). Modified: branches/stable-1.0/platform/win32.c =================================================================== --- branches/stable-1.0/platform/win32.c 2008-02-02 02:32:48 UTC (rev 928) +++ branches/stable-1.0/platform/win32.c 2008-02-13 05:48:57 UTC (rev 929) @@ -78,8 +78,7 @@ { static TCHAR msgbuf[255]; TCHAR *ptr = msgbuf; - - FormatMessage( + DWORD rc = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, @@ -90,6 +89,9 @@ NULL ); + if (rc == 0) + msgbuf = '\0'; /* oh well. */ + /* chop off newlines. */ for (ptr = msgbuf; *ptr; ptr++) { Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-02-02 02:32:48 UTC (rev 928) +++ trunk/CHANGELOG.txt 2008-02-13 05:48:57 UTC (rev 929) @@ -2,6 +2,7 @@ * CHANGELOG. */ +02132008 - Minor Windows fix (thanks, fydo!). 02012008 - lzma fixes (thanks, eH!). 01222008 - Upgraded lzma sdk, lzma.c improvements (thanks, Dennis!). Added zlib README, and updated LICENSE.txt. Modified: trunk/platform/windows.c =================================================================== --- trunk/platform/windows.c 2008-02-02 02:32:48 UTC (rev 928) +++ trunk/platform/windows.c 2008-02-13 05:48:57 UTC (rev 929) @@ -339,6 +339,9 @@ msgbuf, __PHYSFS_ARRAYLEN(msgbuf), NULL); + if (rc == 0) + msgbuf[0] = '\0'; /* oh well. */ + /* chop off newlines. */ for (ptr = msgbuf; *ptr; ptr++) { From DONOTREPLY at icculus.org Wed Feb 20 07:24:11 2008 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 20 Feb 2008 07:24:11 -0500 Subject: r930 - branches/stable-1.0 branches/stable-1.0/archivers trunk trunk/archivers Message-ID: <20080220122411.26420.qmail@icculus.org> Author: icculus Date: 2008-02-20 07:24:10 -0500 (Wed, 20 Feb 2008) New Revision: 930 Modified: branches/stable-1.0/CHANGELOG branches/stable-1.0/archivers/grp.c branches/stable-1.0/archivers/hog.c branches/stable-1.0/archivers/mvl.c branches/stable-1.0/archivers/qpak.c branches/stable-1.0/archivers/wad.c branches/stable-1.0/archivers/zip.c trunk/CHANGELOG.txt trunk/archivers/grp.c trunk/archivers/hog.c trunk/archivers/mvl.c trunk/archivers/qpak.c trunk/archivers/wad.c trunk/archivers/zip.c Log: Various archiver swap and compare functions now check if they are swapping/comparing an item against itself, for efficiency and to prevent overlapping memcpy() calls. Modified: branches/stable-1.0/CHANGELOG =================================================================== --- branches/stable-1.0/CHANGELOG 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/CHANGELOG 2008-02-20 12:24:10 UTC (rev 930) @@ -4,6 +4,9 @@ -- stuff in the stable-1.0 branch, backported from 2.0.0 dev branch, etc --- +02202008 - Various archiver swap and compare functions now check if they are + swapping/comparing an item against itself, for efficiency and + to prevent overlapping memcpy() calls. 02132008 - Minor Windows fix (thanks, fydo!). 01222008 - Added zlib README, and updated LICENSE.txt. 01212008 - Fixed HTTP header in physfshttpd.c. Modified: branches/stable-1.0/archivers/grp.c =================================================================== --- branches/stable-1.0/archivers/grp.c 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/archivers/grp.c 2008-02-20 12:24:10 UTC (rev 930) @@ -263,19 +263,27 @@ static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - GRPentry *a = (GRPentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const GRPentry *a = (const GRPentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* grp_entry_cmp */ static void grp_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - GRPentry tmp; - GRPentry *first = &(((GRPentry *) _a)[one]); - GRPentry *second = &(((GRPentry *) _a)[two]); - memcpy(&tmp, first, sizeof (GRPentry)); - memcpy(first, second, sizeof (GRPentry)); - memcpy(second, &tmp, sizeof (GRPentry)); + if (one != two) + { + GRPentry tmp; + GRPentry *first = &(((GRPentry *) _a)[one]); + GRPentry *second = &(((GRPentry *) _a)[two]); + memcpy(&tmp, first, sizeof (GRPentry)); + memcpy(first, second, sizeof (GRPentry)); + memcpy(second, &tmp, sizeof (GRPentry)); + } /* if */ } /* grp_entry_swap */ Modified: branches/stable-1.0/archivers/hog.c =================================================================== --- branches/stable-1.0/archivers/hog.c 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/archivers/hog.c 2008-02-20 12:24:10 UTC (rev 930) @@ -300,19 +300,27 @@ static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - HOGentry *a = (HOGentry *) _a; - return(__PHYSFS_platformStricmp(a[one].name, a[two].name)); + if (one != two) + { + const HOGentry *a = (const HOGentry *) _a; + return(__PHYSFS_platformStricmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* hog_entry_cmp */ static void hog_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - HOGentry tmp; - HOGentry *first = &(((HOGentry *) _a)[one]); - HOGentry *second = &(((HOGentry *) _a)[two]); - memcpy(&tmp, first, sizeof (HOGentry)); - memcpy(first, second, sizeof (HOGentry)); - memcpy(second, &tmp, sizeof (HOGentry)); + if (one != two) + { + HOGentry tmp; + HOGentry *first = &(((HOGentry *) _a)[one]); + HOGentry *second = &(((HOGentry *) _a)[two]); + memcpy(&tmp, first, sizeof (HOGentry)); + memcpy(first, second, sizeof (HOGentry)); + memcpy(second, &tmp, sizeof (HOGentry)); + } /* if */ } /* hog_entry_swap */ Modified: branches/stable-1.0/archivers/mvl.c =================================================================== --- branches/stable-1.0/archivers/mvl.c 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/archivers/mvl.c 2008-02-20 12:24:10 UTC (rev 930) @@ -266,19 +266,27 @@ static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - MVLentry *a = (MVLentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const MVLentry *a = (const MVLentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* mvl_entry_cmp */ static void mvl_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - MVLentry tmp; - MVLentry *first = &(((MVLentry *) _a)[one]); - MVLentry *second = &(((MVLentry *) _a)[two]); - memcpy(&tmp, first, sizeof (MVLentry)); - memcpy(first, second, sizeof (MVLentry)); - memcpy(second, &tmp, sizeof (MVLentry)); + if (one != two) + { + MVLentry tmp; + MVLentry *first = &(((MVLentry *) _a)[one]); + MVLentry *second = &(((MVLentry *) _a)[two]); + memcpy(&tmp, first, sizeof (MVLentry)); + memcpy(first, second, sizeof (MVLentry)); + memcpy(second, &tmp, sizeof (MVLentry)); + } /* if */ } /* mvl_entry_swap */ Modified: branches/stable-1.0/archivers/qpak.c =================================================================== --- branches/stable-1.0/archivers/qpak.c 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/archivers/qpak.c 2008-02-20 12:24:10 UTC (rev 930) @@ -296,19 +296,27 @@ static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - QPAKentry *a = (QPAKentry *) _a; - return(QPAK_strcmp(a[one].name, a[two].name)); + if (one != two) + { + const QPAKentry *a = (const QPAKentry *) _a; + return(QPAK_strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* qpak_entry_cmp */ static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - QPAKentry tmp; - QPAKentry *first = &(((QPAKentry *) _a)[one]); - QPAKentry *second = &(((QPAKentry *) _a)[two]); - memcpy(&tmp, first, sizeof (QPAKentry)); - memcpy(first, second, sizeof (QPAKentry)); - memcpy(second, &tmp, sizeof (QPAKentry)); + if (one != two) + { + QPAKentry tmp; + QPAKentry *first = &(((QPAKentry *) _a)[one]); + QPAKentry *second = &(((QPAKentry *) _a)[two]); + memcpy(&tmp, first, sizeof (QPAKentry)); + memcpy(first, second, sizeof (QPAKentry)); + memcpy(second, &tmp, sizeof (QPAKentry)); + } /* if */ } /* qpak_entry_swap */ Modified: branches/stable-1.0/archivers/wad.c =================================================================== --- branches/stable-1.0/archivers/wad.c 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/archivers/wad.c 2008-02-20 12:24:10 UTC (rev 930) @@ -287,19 +287,27 @@ static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - WADentry *a = (WADentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const WADentry *a = (const WADentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* wad_entry_cmp */ static void wad_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - WADentry tmp; - WADentry *first = &(((WADentry *) _a)[one]); - WADentry *second = &(((WADentry *) _a)[two]); - memcpy(&tmp, first, sizeof (WADentry)); - memcpy(first, second, sizeof (WADentry)); - memcpy(second, &tmp, sizeof (WADentry)); + if (one != two) + { + WADentry tmp; + WADentry *first = &(((WADentry *) _a)[one]); + WADentry *second = &(((WADentry *) _a)[two]); + memcpy(&tmp, first, sizeof (WADentry)); + memcpy(first, second, sizeof (WADentry)); + memcpy(second, &tmp, sizeof (WADentry)); + } /* if */ } /* wad_entry_swap */ Modified: branches/stable-1.0/archivers/zip.c =================================================================== --- branches/stable-1.0/archivers/zip.c 2008-02-13 05:48:57 UTC (rev 929) +++ branches/stable-1.0/archivers/zip.c 2008-02-20 12:24:10 UTC (rev 930) @@ -992,19 +992,27 @@ static int zip_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - ZIPentry *a = (ZIPentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const ZIPentry *a = (const ZIPentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* zip_entry_cmp */ static void zip_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - ZIPentry tmp; - ZIPentry *first = &(((ZIPentry *) _a)[one]); - ZIPentry *second = &(((ZIPentry *) _a)[two]); - memcpy(&tmp, first, sizeof (ZIPentry)); - memcpy(first, second, sizeof (ZIPentry)); - memcpy(second, &tmp, sizeof (ZIPentry)); + if (one != two) + { + ZIPentry tmp; + ZIPentry *first = &(((ZIPentry *) _a)[one]); + ZIPentry *second = &(((ZIPentry *) _a)[two]); + memcpy(&tmp, first, sizeof (ZIPentry)); + memcpy(first, second, sizeof (ZIPentry)); + memcpy(second, &tmp, sizeof (ZIPentry)); + } /* if */ } /* zip_entry_swap */ Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/CHANGELOG.txt 2008-02-20 12:24:10 UTC (rev 930) @@ -2,6 +2,9 @@ * CHANGELOG. */ +02202008 - Various archiver swap and compare functions now check if they are + swapping/comparing an item against itself, for efficiency and + to prevent overlapping memcpy() calls. 02132008 - Minor Windows fix (thanks, fydo!). 02012008 - lzma fixes (thanks, eH!). 01222008 - Upgraded lzma sdk, lzma.c improvements (thanks, Dennis!). Modified: trunk/archivers/grp.c =================================================================== --- trunk/archivers/grp.c 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/archivers/grp.c 2008-02-20 12:24:10 UTC (rev 930) @@ -191,19 +191,27 @@ static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - GRPentry *a = (GRPentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const GRPentry *a = (const GRPentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* grp_entry_cmp */ static void grp_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - GRPentry tmp; - GRPentry *first = &(((GRPentry *) _a)[one]); - GRPentry *second = &(((GRPentry *) _a)[two]); - memcpy(&tmp, first, sizeof (GRPentry)); - memcpy(first, second, sizeof (GRPentry)); - memcpy(second, &tmp, sizeof (GRPentry)); + if (one != two) + { + GRPentry tmp; + GRPentry *first = &(((GRPentry *) _a)[one]); + GRPentry *second = &(((GRPentry *) _a)[two]); + memcpy(&tmp, first, sizeof (GRPentry)); + memcpy(first, second, sizeof (GRPentry)); + memcpy(second, &tmp, sizeof (GRPentry)); + } /* if */ } /* grp_entry_swap */ Modified: trunk/archivers/hog.c =================================================================== --- trunk/archivers/hog.c 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/archivers/hog.c 2008-02-20 12:24:10 UTC (rev 930) @@ -228,19 +228,27 @@ static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - HOGentry *a = (HOGentry *) _a; - return(__PHYSFS_stricmpASCII(a[one].name, a[two].name)); + if (one != two) + { + const HOGentry *a = (const HOGentry *) _a; + return(__PHYSFS_stricmpASCII(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* hog_entry_cmp */ static void hog_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - HOGentry tmp; - HOGentry *first = &(((HOGentry *) _a)[one]); - HOGentry *second = &(((HOGentry *) _a)[two]); - memcpy(&tmp, first, sizeof (HOGentry)); - memcpy(first, second, sizeof (HOGentry)); - memcpy(second, &tmp, sizeof (HOGentry)); + if (one != two) + { + HOGentry tmp; + HOGentry *first = &(((HOGentry *) _a)[one]); + HOGentry *second = &(((HOGentry *) _a)[two]); + memcpy(&tmp, first, sizeof (HOGentry)); + memcpy(first, second, sizeof (HOGentry)); + memcpy(second, &tmp, sizeof (HOGentry)); + } /* if */ } /* hog_entry_swap */ Modified: trunk/archivers/mvl.c =================================================================== --- trunk/archivers/mvl.c 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/archivers/mvl.c 2008-02-20 12:24:10 UTC (rev 930) @@ -194,19 +194,27 @@ static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - MVLentry *a = (MVLentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const MVLentry *a = (const MVLentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* mvl_entry_cmp */ static void mvl_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - MVLentry tmp; - MVLentry *first = &(((MVLentry *) _a)[one]); - MVLentry *second = &(((MVLentry *) _a)[two]); - memcpy(&tmp, first, sizeof (MVLentry)); - memcpy(first, second, sizeof (MVLentry)); - memcpy(second, &tmp, sizeof (MVLentry)); + if (one != two) + { + MVLentry tmp; + MVLentry *first = &(((MVLentry *) _a)[one]); + MVLentry *second = &(((MVLentry *) _a)[two]); + memcpy(&tmp, first, sizeof (MVLentry)); + memcpy(first, second, sizeof (MVLentry)); + memcpy(second, &tmp, sizeof (MVLentry)); + } /* if */ } /* mvl_entry_swap */ Modified: trunk/archivers/qpak.c =================================================================== --- trunk/archivers/qpak.c 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/archivers/qpak.c 2008-02-20 12:24:10 UTC (rev 930) @@ -217,19 +217,27 @@ static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - QPAKentry *a = (QPAKentry *) _a; - return(QPAK_strcmp(a[one].name, a[two].name)); + if (one != two) + { + const QPAKentry *a = (const QPAKentry *) _a; + return(QPAK_strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* qpak_entry_cmp */ static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - QPAKentry tmp; - QPAKentry *first = &(((QPAKentry *) _a)[one]); - QPAKentry *second = &(((QPAKentry *) _a)[two]); - memcpy(&tmp, first, sizeof (QPAKentry)); - memcpy(first, second, sizeof (QPAKentry)); - memcpy(second, &tmp, sizeof (QPAKentry)); + if (one != two) + { + QPAKentry tmp; + QPAKentry *first = &(((QPAKentry *) _a)[one]); + QPAKentry *second = &(((QPAKentry *) _a)[two]); + memcpy(&tmp, first, sizeof (QPAKentry)); + memcpy(first, second, sizeof (QPAKentry)); + memcpy(second, &tmp, sizeof (QPAKentry)); + } /* if */ } /* qpak_entry_swap */ Modified: trunk/archivers/wad.c =================================================================== --- trunk/archivers/wad.c 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/archivers/wad.c 2008-02-20 12:24:10 UTC (rev 930) @@ -215,19 +215,27 @@ static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - WADentry *a = (WADentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const WADentry *a = (const WADentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* wad_entry_cmp */ static void wad_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - WADentry tmp; - WADentry *first = &(((WADentry *) _a)[one]); - WADentry *second = &(((WADentry *) _a)[two]); - memcpy(&tmp, first, sizeof (WADentry)); - memcpy(first, second, sizeof (WADentry)); - memcpy(second, &tmp, sizeof (WADentry)); + if (one != two) + { + WADentry tmp; + WADentry *first = &(((WADentry *) _a)[one]); + WADentry *second = &(((WADentry *) _a)[two]); + memcpy(&tmp, first, sizeof (WADentry)); + memcpy(first, second, sizeof (WADentry)); + memcpy(second, &tmp, sizeof (WADentry)); + } /* if */ } /* wad_entry_swap */ Modified: trunk/archivers/zip.c =================================================================== --- trunk/archivers/zip.c 2008-02-13 05:48:57 UTC (rev 929) +++ trunk/archivers/zip.c 2008-02-20 12:24:10 UTC (rev 930) @@ -952,19 +952,27 @@ static int zip_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - ZIPentry *a = (ZIPentry *) _a; - return(strcmp(a[one].name, a[two].name)); + if (one != two) + { + const ZIPentry *a = (const ZIPentry *) _a; + return(strcmp(a[one].name, a[two].name)); + } /* if */ + + return 0; } /* zip_entry_cmp */ static void zip_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) { - ZIPentry tmp; - ZIPentry *first = &(((ZIPentry *) _a)[one]); - ZIPentry *second = &(((ZIPentry *) _a)[two]); - memcpy(&tmp, first, sizeof (ZIPentry)); - memcpy(first, second, sizeof (ZIPentry)); - memcpy(second, &tmp, sizeof (ZIPentry)); + if (one != two) + { + ZIPentry tmp; + ZIPentry *first = &(((ZIPentry *) _a)[one]); + ZIPentry *second = &(((ZIPentry *) _a)[two]); + memcpy(&tmp, first, sizeof (ZIPentry)); + memcpy(first, second, sizeof (ZIPentry)); + memcpy(second, &tmp, sizeof (ZIPentry)); + } /* if */ } /* zip_entry_swap */