diff options
author | Haru <haru@dotalux.com> | 2020-04-06 05:18:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 05:18:14 +0200 |
commit | 1ae5a4cb1003b9c336c315142e66a5e5b7f3ca32 (patch) | |
tree | 74d92f0d0f3cda2a2de3e9d7b2c2b6203afc1e48 | |
parent | ab640e4745afdf771709dce826aee97e0e4670fd (diff) | |
parent | 58c4ce73b9fdc1d67a928e37742510bf49bb7dbc (diff) | |
download | hercules-1ae5a4cb1003b9c336c315142e66a5e5b7f3ca32.tar.gz hercules-1ae5a4cb1003b9c336c315142e66a5e5b7f3ca32.tar.bz2 hercules-1ae5a4cb1003b9c336c315142e66a5e5b7f3ca32.tar.xz hercules-1ae5a4cb1003b9c336c315142e66a5e5b7f3ca32.zip |
Merge pull request #2682 from HerculesWS/questinfo_memory_fixes
Questinfo memory violation and handling fixes
-rw-r--r-- | src/map/map.c | 10 | ||||
-rw-r--r-- | src/map/map.h | 2 | ||||
-rw-r--r-- | src/map/quest.c | 2 | ||||
-rw-r--r-- | src/map/script.c | 5 |
4 files changed, 12 insertions, 7 deletions
diff --git a/src/map/map.c b/src/map/map.c index defa56b2e..b2c9c77c3 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -6047,11 +6047,15 @@ static bool map_add_questinfo(int m, struct npc_data *nd) nullpo_retr(false, nd); Assert_retr(false, m >= 0 && m < map->count); - if (&VECTOR_LAST(map->list[m].qi_list) == nd) + int i; + ARR_FIND(0, VECTOR_LENGTH(map->list[m].qi_list), i, VECTOR_INDEX(map->list[m].qi_list, i) == nd); + + if (i < VECTOR_LENGTH(map->list[m].qi_list)) { return false; + } VECTOR_ENSURE(map->list[m].qi_list, 1, 1); - VECTOR_PUSH(map->list[m].qi_list, *nd); + VECTOR_PUSH(map->list[m].qi_list, nd); return true; } @@ -6062,7 +6066,7 @@ static bool map_remove_questinfo(int m, struct npc_data *nd) Assert_retr(false, m >= 0 && m < map->count); int i; - ARR_FIND(0, VECTOR_LENGTH(map->list[m].qi_list), i, &VECTOR_INDEX(map->list[m].qi_list, i) == nd); + ARR_FIND(0, VECTOR_LENGTH(map->list[m].qi_list), i, VECTOR_INDEX(map->list[m].qi_list, i) == nd); if (i != VECTOR_LENGTH(map->list[m].qi_list)) { VECTOR_ERASE(map->list[m].qi_list, i); return true; diff --git a/src/map/map.h b/src/map/map.h index a876539d0..2de6df2f7 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -846,7 +846,7 @@ struct map_data { } cell_buf; /* questinfo entries list */ - VECTOR_DECL(struct npc_data) qi_list; + VECTOR_DECL(struct npc_data *) qi_list; /* speeds up clif_updatestatus processing by causing hpmeter to run only when someone with the permission can view it */ unsigned short hpmeter_visible; diff --git a/src/map/quest.c b/src/map/quest.c index 10ea668a6..217acfa19 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -675,7 +675,7 @@ static void quest_questinfo_refresh(struct map_session_data *sd) nullpo_retv(sd); for (int i = 0; i < VECTOR_LENGTH(map->list[sd->bl.m].qi_list); i++) { - struct npc_data *nd = &VECTOR_INDEX(map->list[sd->bl.m].qi_list, i); + struct npc_data *nd = VECTOR_INDEX(map->list[sd->bl.m].qi_list, i); int j; ARR_FIND(0, VECTOR_LENGTH(nd->qi_data), j, quest->questinfo_validate(sd, &VECTOR_INDEX(nd->qi_data, j)) == true); diff --git a/src/map/script.c b/src/map/script.c index 3d5534a47..c08f5e829 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -22085,12 +22085,13 @@ static BUILDIN(setquestinfo) return false; } - qi = &VECTOR_LAST(nd->qi_data); - if (qi == NULL) { + if (VECTOR_LENGTH(nd->qi_data) == 0) { ShowWarning("buildin_setquestinfo: no valide questinfo data has been found for this npc.\n"); return false; } + qi = &VECTOR_LAST(nd->qi_data); + switch (type) { case QINFO_JOB: { |