From 643c956ceff2c6a9ecfb59ad0653e1634350d4fb Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 11 Sep 2016 01:31:00 +0200 Subject: Changed GD_MAX check to be non-inclusive - GD_MAX is not a valid guild skill ID - Fixes Coverity CID 152761 - Follow-up to 0f803e7 Signed-off-by: Haru --- src/map/script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index 7db3736e3..efdc3557b 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -9490,7 +9490,7 @@ BUILDIN(guildskill) { skill_id = ( script_isstringtype(st,2) ? skill->name2id(script_getstr(st,2)) : script_getnum(st,2) ); level = script_getnum(st,3); - if (skill_id < GD_SKILLBASE || skill_id > GD_MAX) + if (skill_id < GD_SKILLBASE || skill_id >= GD_MAX) return true; // not guild skill id = skill_id - GD_SKILLBASE; -- cgit v1.2.3-70-g09d2 From 2b30a403f03c91b119e2f3ba1491d308cccba924 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 11 Sep 2016 01:49:09 +0200 Subject: 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 --- src/map/script.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') 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); -- cgit v1.2.3-70-g09d2