From 3a433130bb507f5cbf85e14569f03c16c8da179b Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 18 Jan 2015 20:31:37 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/include/build.h | 3 ++- polymer/eduke32/build/src/engine.c | 3 ++- polymer/eduke32/source/premap.c | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index b398d1d27..e45d1bb6f 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -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; diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 334d4a82a..2ddd3ca80 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -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); diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 1d653c318..34b05a347 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -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); }