Fix bsearch() call for user G_LoadMapHack(): don't access nonexistent storage. DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@4933 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2015-01-18 20:31:37 +00:00
parent 80da69f6a0
commit 3a433130bb
3 changed files with 8 additions and 3 deletions

View file

@ -550,13 +550,14 @@ typedef struct {
EXTERN int32_t guniqhudid;
EXTERN int32_t spritesortcnt;
extern int32_t g_loadedMapVersion;
extern uint8_t g_loadedMapMD4[16];
typedef struct {
char *mhkfile;
char *title;
uint8_t md4[16];
} usermaphack_t;
extern usermaphack_t g_loadedMapHack;
extern int32_t compare_usermaphacks(const void *, const void *);
extern usermaphack_t *usermaphacks;
extern int32_t num_usermaphacks;

View file

@ -83,6 +83,7 @@ float debug1, debug2;
int32_t mapversion=7; // JBF 20040211: default mapversion to 7
int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new)
usermaphack_t g_loadedMapHack; // used only for the MD4 part
uint8_t g_loadedMapMD4[16];
int32_t compare_usermaphacks(const void *a, const void *b)
@ -10791,7 +10792,7 @@ skip_reading_mapbin:
int32_t boardsize = kfilelength(fil);
uint8_t *fullboard = (uint8_t*)Xmalloc(boardsize);
kread(fil, fullboard, boardsize);
md4once(fullboard, boardsize, g_loadedMapMD4);
md4once(fullboard, boardsize, g_loadedMapHack.md4);
Bfree(fullboard);
kclose(fil);

View file

@ -1714,7 +1714,10 @@ static void G_LoadMapHack(char *outbuf, const char *filename)
if (G_TryMapHack(outbuf))
{
usermaphack_t *mapinfo = (usermaphack_t*)bsearch(g_loadedMapMD4 - offsetof(usermaphack_t, md4), usermaphacks, num_usermaphacks, sizeof(usermaphack_t), compare_usermaphacks);
usermaphack_t *mapinfo = (usermaphack_t*)bsearch(
&g_loadedMapHack, usermaphacks, num_usermaphacks, sizeof(usermaphack_t),
compare_usermaphacks);
if (mapinfo)
G_TryMapHack(mapinfo->mhkfile);
}