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.
This commit is contained in:
parent
0e720678af
commit
32fb2ab4a9
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
-- stuff in the stable-1.0 branch, backported from 2.0.0 dev branch, etc ---
|
-- 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!).
|
02132008 - Minor Windows fix (thanks, fydo!).
|
||||||
01222008 - Added zlib README, and updated LICENSE.txt.
|
01222008 - Added zlib README, and updated LICENSE.txt.
|
||||||
01212008 - Fixed HTTP header in physfshttpd.c.
|
01212008 - Fixed HTTP header in physfshttpd.c.
|
||||||
|
|
|
@ -263,19 +263,27 @@ static int GRP_isArchive(const char *filename, int forWriting)
|
||||||
|
|
||||||
static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static int grp_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
GRPentry *a = (GRPentry *) _a;
|
if (one != two)
|
||||||
return(strcmp(a[one].name, a[two].name));
|
{
|
||||||
|
const GRPentry *a = (const GRPentry *) _a;
|
||||||
|
return(strcmp(a[one].name, a[two].name));
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
return 0;
|
||||||
} /* grp_entry_cmp */
|
} /* grp_entry_cmp */
|
||||||
|
|
||||||
|
|
||||||
static void grp_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static void grp_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
GRPentry tmp;
|
if (one != two)
|
||||||
GRPentry *first = &(((GRPentry *) _a)[one]);
|
{
|
||||||
GRPentry *second = &(((GRPentry *) _a)[two]);
|
GRPentry tmp;
|
||||||
memcpy(&tmp, first, sizeof (GRPentry));
|
GRPentry *first = &(((GRPentry *) _a)[one]);
|
||||||
memcpy(first, second, sizeof (GRPentry));
|
GRPentry *second = &(((GRPentry *) _a)[two]);
|
||||||
memcpy(second, &tmp, sizeof (GRPentry));
|
memcpy(&tmp, first, sizeof (GRPentry));
|
||||||
|
memcpy(first, second, sizeof (GRPentry));
|
||||||
|
memcpy(second, &tmp, sizeof (GRPentry));
|
||||||
|
} /* if */
|
||||||
} /* grp_entry_swap */
|
} /* grp_entry_swap */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -300,19 +300,27 @@ static int HOG_isArchive(const char *filename, int forWriting)
|
||||||
|
|
||||||
static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static int hog_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
HOGentry *a = (HOGentry *) _a;
|
if (one != two)
|
||||||
return(__PHYSFS_platformStricmp(a[one].name, a[two].name));
|
{
|
||||||
|
const HOGentry *a = (const HOGentry *) _a;
|
||||||
|
return(__PHYSFS_platformStricmp(a[one].name, a[two].name));
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
return 0;
|
||||||
} /* hog_entry_cmp */
|
} /* hog_entry_cmp */
|
||||||
|
|
||||||
|
|
||||||
static void hog_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static void hog_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
HOGentry tmp;
|
if (one != two)
|
||||||
HOGentry *first = &(((HOGentry *) _a)[one]);
|
{
|
||||||
HOGentry *second = &(((HOGentry *) _a)[two]);
|
HOGentry tmp;
|
||||||
memcpy(&tmp, first, sizeof (HOGentry));
|
HOGentry *first = &(((HOGentry *) _a)[one]);
|
||||||
memcpy(first, second, sizeof (HOGentry));
|
HOGentry *second = &(((HOGentry *) _a)[two]);
|
||||||
memcpy(second, &tmp, sizeof (HOGentry));
|
memcpy(&tmp, first, sizeof (HOGentry));
|
||||||
|
memcpy(first, second, sizeof (HOGentry));
|
||||||
|
memcpy(second, &tmp, sizeof (HOGentry));
|
||||||
|
} /* if */
|
||||||
} /* hog_entry_swap */
|
} /* hog_entry_swap */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -266,19 +266,27 @@ static int MVL_isArchive(const char *filename, int forWriting)
|
||||||
|
|
||||||
static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static int mvl_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
MVLentry *a = (MVLentry *) _a;
|
if (one != two)
|
||||||
return(strcmp(a[one].name, a[two].name));
|
{
|
||||||
|
const MVLentry *a = (const MVLentry *) _a;
|
||||||
|
return(strcmp(a[one].name, a[two].name));
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
return 0;
|
||||||
} /* mvl_entry_cmp */
|
} /* mvl_entry_cmp */
|
||||||
|
|
||||||
|
|
||||||
static void mvl_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static void mvl_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
MVLentry tmp;
|
if (one != two)
|
||||||
MVLentry *first = &(((MVLentry *) _a)[one]);
|
{
|
||||||
MVLentry *second = &(((MVLentry *) _a)[two]);
|
MVLentry tmp;
|
||||||
memcpy(&tmp, first, sizeof (MVLentry));
|
MVLentry *first = &(((MVLentry *) _a)[one]);
|
||||||
memcpy(first, second, sizeof (MVLentry));
|
MVLentry *second = &(((MVLentry *) _a)[two]);
|
||||||
memcpy(second, &tmp, sizeof (MVLentry));
|
memcpy(&tmp, first, sizeof (MVLentry));
|
||||||
|
memcpy(first, second, sizeof (MVLentry));
|
||||||
|
memcpy(second, &tmp, sizeof (MVLentry));
|
||||||
|
} /* if */
|
||||||
} /* mvl_entry_swap */
|
} /* mvl_entry_swap */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -296,19 +296,27 @@ static int QPAK_isArchive(const char *filename, int forWriting)
|
||||||
|
|
||||||
static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static int qpak_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
QPAKentry *a = (QPAKentry *) _a;
|
if (one != two)
|
||||||
return(QPAK_strcmp(a[one].name, a[two].name));
|
{
|
||||||
|
const QPAKentry *a = (const QPAKentry *) _a;
|
||||||
|
return(QPAK_strcmp(a[one].name, a[two].name));
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
return 0;
|
||||||
} /* qpak_entry_cmp */
|
} /* qpak_entry_cmp */
|
||||||
|
|
||||||
|
|
||||||
static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static void qpak_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
QPAKentry tmp;
|
if (one != two)
|
||||||
QPAKentry *first = &(((QPAKentry *) _a)[one]);
|
{
|
||||||
QPAKentry *second = &(((QPAKentry *) _a)[two]);
|
QPAKentry tmp;
|
||||||
memcpy(&tmp, first, sizeof (QPAKentry));
|
QPAKentry *first = &(((QPAKentry *) _a)[one]);
|
||||||
memcpy(first, second, sizeof (QPAKentry));
|
QPAKentry *second = &(((QPAKentry *) _a)[two]);
|
||||||
memcpy(second, &tmp, sizeof (QPAKentry));
|
memcpy(&tmp, first, sizeof (QPAKentry));
|
||||||
|
memcpy(first, second, sizeof (QPAKentry));
|
||||||
|
memcpy(second, &tmp, sizeof (QPAKentry));
|
||||||
|
} /* if */
|
||||||
} /* qpak_entry_swap */
|
} /* qpak_entry_swap */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -287,19 +287,27 @@ static int WAD_isArchive(const char *filename, int forWriting)
|
||||||
|
|
||||||
static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
WADentry *a = (WADentry *) _a;
|
if (one != two)
|
||||||
return(strcmp(a[one].name, a[two].name));
|
{
|
||||||
|
const WADentry *a = (const WADentry *) _a;
|
||||||
|
return(strcmp(a[one].name, a[two].name));
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
return 0;
|
||||||
} /* wad_entry_cmp */
|
} /* wad_entry_cmp */
|
||||||
|
|
||||||
|
|
||||||
static void wad_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static void wad_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
WADentry tmp;
|
if (one != two)
|
||||||
WADentry *first = &(((WADentry *) _a)[one]);
|
{
|
||||||
WADentry *second = &(((WADentry *) _a)[two]);
|
WADentry tmp;
|
||||||
memcpy(&tmp, first, sizeof (WADentry));
|
WADentry *first = &(((WADentry *) _a)[one]);
|
||||||
memcpy(first, second, sizeof (WADentry));
|
WADentry *second = &(((WADentry *) _a)[two]);
|
||||||
memcpy(second, &tmp, sizeof (WADentry));
|
memcpy(&tmp, first, sizeof (WADentry));
|
||||||
|
memcpy(first, second, sizeof (WADentry));
|
||||||
|
memcpy(second, &tmp, sizeof (WADentry));
|
||||||
|
} /* if */
|
||||||
} /* wad_entry_swap */
|
} /* wad_entry_swap */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -992,19 +992,27 @@ zip_load_entry_puked:
|
||||||
|
|
||||||
static int zip_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static int zip_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
ZIPentry *a = (ZIPentry *) _a;
|
if (one != two)
|
||||||
return(strcmp(a[one].name, a[two].name));
|
{
|
||||||
|
const ZIPentry *a = (const ZIPentry *) _a;
|
||||||
|
return(strcmp(a[one].name, a[two].name));
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
return 0;
|
||||||
} /* zip_entry_cmp */
|
} /* zip_entry_cmp */
|
||||||
|
|
||||||
|
|
||||||
static void zip_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
static void zip_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
|
||||||
{
|
{
|
||||||
ZIPentry tmp;
|
if (one != two)
|
||||||
ZIPentry *first = &(((ZIPentry *) _a)[one]);
|
{
|
||||||
ZIPentry *second = &(((ZIPentry *) _a)[two]);
|
ZIPentry tmp;
|
||||||
memcpy(&tmp, first, sizeof (ZIPentry));
|
ZIPentry *first = &(((ZIPentry *) _a)[one]);
|
||||||
memcpy(first, second, sizeof (ZIPentry));
|
ZIPentry *second = &(((ZIPentry *) _a)[two]);
|
||||||
memcpy(second, &tmp, sizeof (ZIPentry));
|
memcpy(&tmp, first, sizeof (ZIPentry));
|
||||||
|
memcpy(first, second, sizeof (ZIPentry));
|
||||||
|
memcpy(second, &tmp, sizeof (ZIPentry));
|
||||||
|
} /* if */
|
||||||
} /* zip_entry_swap */
|
} /* zip_entry_swap */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue