summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-09-11 01:49:09 +0200
committerHaru <haru@dotalux.com>2016-09-11 01:49:09 +0200
commit2b30a403f03c91b119e2f3ba1491d308cccba924 (patch)
treebe446139fae63cd1bd67fc276a1ad14c870022e6 /src/map/script.c
parent643c956ceff2c6a9ecfb59ad0653e1634350d4fb (diff)
downloadhercules-2b30a403f03c91b119e2f3ba1491d308cccba924.tar.gz
hercules-2b30a403f03c91b119e2f3ba1491d308cccba924.tar.bz2
hercules-2b30a403f03c91b119e2f3ba1491d308cccba924.tar.xz
hercules-2b30a403f03c91b119e2f3ba1491d308cccba924.zip
Clarified/rewritten part of script_array_ensure_zero()
- There exists a case where st is NULL, such as when called by script->cleararray_pc(). This documents such possibility. - Fixes Coverity CID 152760 - Follow-up to 0f803e7 Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/map/script.c b/src/map/script.c
index efdc3557b..2633c1e5f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2970,17 +2970,18 @@ const void *get_val2(struct script_state *st, int64 uid, struct reg_db *ref)
**/
void script_array_ensure_zero(struct script_state *st, struct map_session_data *sd, int64 uid, struct reg_db *ref) {
const char *name = script->get_str(script_getvarid(uid));
- // is here st can be null pointer and st->rid is wrong?
- struct reg_db *src;
+ struct reg_db *src = NULL;
bool insert = false;
- nullpo_retv(st);
- src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name, ref);
-
- if (sd && !st) {
- /* when sd comes, st isn't available */
+ if (st == NULL) {
+ // Special case with no st available, only sd
+ nullpo_retv(sd);
+ src = script->array_src(NULL, sd, name, ref);
insert = true;
} else {
+ if (sd == NULL && st->rid != 0)
+ sd = map->id2sd(st->rid); // Retrieve the missing sd
+ src = script->array_src(st, sd, name, ref);
if( is_string_variable(name) ) {
const char *str = script->get_val2(st, uid, ref);
if (str != NULL && *str != '\0')
@@ -3121,10 +3122,12 @@ struct reg_db *script_array_src(struct script_state *st, struct map_session_data
src = &mapreg->regs;
break;
case '.':/* npc/script */
- if( ref )
+ if (ref != NULL) {
src = ref;
- else
+ } else {
+ nullpo_retr(NULL, st);
src = (name[1] == '@') ? &st->stack->scope : &st->script->local;
+ }
break;
case '\'':/* instance */
nullpo_retr(NULL, st);