From 9e6e0e0790c6548e45eda36d7699fea51502970d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 17 Aug 2015 17:01:40 +0300 Subject: Dont call memset with null pointer. --- src/common/malloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/malloc.c b/src/common/malloc.c index d5a979e77..63de90cb3 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -343,7 +343,8 @@ void *mmalloc_(size_t size, const char *file, int line, const char *func) { void *mcalloc_(size_t num, size_t size, const char *file, int line, const char *func) { void *p = iMalloc->malloc(num * size,file,line,func); - memset(p,0,num * size); + if (p) + memset(p, 0, num * size); return p; } -- cgit v1.2.3-70-g09d2 From c31fa9cd48352db8fde5ef91f38bef8ad9507431 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 17 Aug 2015 17:35:50 +0300 Subject: Fix wrong index access and probably wrong hp/sp calculation. Closes #653 --- configure | 2 +- src/map/status.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 7587cf5cd..fbf36aa38 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in e27c744. +# From configure.in afa7ec2. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69. # diff --git a/src/map/status.c b/src/map/status.c index 4fc975268..720a02494 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -12067,7 +12067,13 @@ void status_read_job_db_sub(int idx, const char *name, config_setting_t *jdb) status->dbs->HP_table[idx][i] = status->dbs->HP_table[iidx][i]; } base = (i > 1 ? status->dbs->HP_table[idx][1] : 35); // Safe value if none are specified - avg_increment = (i > 2 ? (status->dbs->HP_table[idx][i] - base) / (i-1) : 5); // Safe value if none are specified + if (i > 2) { + if (i >= MAX_LEVEL + 1) + i = MAX_LEVEL; + avg_increment = (status->dbs->HP_table[idx][i] - base) / (i - 1); + } else { + avg_increment = 5; + } for ( ; i <= pc->max_level[idx][0]; i++) { status->dbs->HP_table[idx][i] = min(base + avg_increment * i, battle_config.max_hp); } @@ -12076,7 +12082,13 @@ void status_read_job_db_sub(int idx, const char *name, config_setting_t *jdb) status->dbs->SP_table[idx][i] = status->dbs->SP_table[iidx][i]; } base = (i > 1 ? status->dbs->SP_table[idx][1] : 10); // Safe value if none are specified - avg_increment = (i > 2 ? (status->dbs->SP_table[idx][i] - base) / (i-1) : 1); // Safe value if none are specified + if (i > 2) { + if (i >= MAX_LEVEL + 1) + i = MAX_LEVEL; + avg_increment = (status->dbs->SP_table[idx][i] - base) / (i - 1); + } else { + avg_increment = 1; + } for ( ; i <= pc->max_level[idx][0]; i++) { status->dbs->SP_table[idx][i] = min(base + avg_increment * i, battle_config.max_sp); } @@ -12096,7 +12108,13 @@ void status_read_job_db_sub(int idx, const char *name, config_setting_t *jdb) status->dbs->HP_table[idx][i] = status->dbs->HP_table[iidx][i]; } base = (i > 1 ? status->dbs->HP_table[idx][1] : 35); // Safe value if none are specified - avg_increment = (i > 2 ? (status->dbs->HP_table[idx][i] - base) / (i-1) : 5); // Safe value if none are specified + if (i > 2) { + if (i >= MAX_LEVEL + 1) + i = MAX_LEVEL; + avg_increment = (status->dbs->HP_table[idx][i] - base) / (i - 1); + } else { + avg_increment = 5; + } for ( ; i <= pc->max_level[idx][0]; i++) { status->dbs->HP_table[idx][i] = min(base + avg_increment * i, battle_config.max_hp); } @@ -12116,7 +12134,13 @@ void status_read_job_db_sub(int idx, const char *name, config_setting_t *jdb) status->dbs->SP_table[idx][i] = status->dbs->SP_table[iidx][i]; } base = (i > 1 ? status->dbs->SP_table[idx][1] : 10); // Safe value if none are specified - avg_increment = (i > 2 ? (status->dbs->SP_table[idx][i] - base) / (i-1) : 1); // Safe value if none are specified + if (i > 2) { + if (i >= MAX_LEVEL + 1) + i = MAX_LEVEL; + avg_increment = (status->dbs->SP_table[idx][i] - base) / (i - 1); + } else { + avg_increment = 1; + } for ( ; i <= pc->max_level[idx][0]; i++) { status->dbs->SP_table[idx][i] = min(avg_increment * i, battle_config.max_sp); } @@ -12152,7 +12176,13 @@ void status_read_job_db_sub(int idx, const char *name, config_setting_t *jdb) status->dbs->HP_table[idx][++level] = min(i32, battle_config.max_hp); } base = (level > 0 ? status->dbs->HP_table[idx][1] : 35); // Safe value if none are specified - avg_increment = (level > 1 ? (status->dbs->HP_table[idx][level] - base) / level : 5); // Safe value if none are specified + if (level > 2) { + if (level >= MAX_LEVEL + 1) + level = MAX_LEVEL; + avg_increment = (status->dbs->HP_table[idx][level] - base) / level; + } else { + avg_increment = 5; + } for (++level; level <= pc->max_level[idx][0]; ++level) { /* limit only to possible maximum level of the given class */ status->dbs->HP_table[idx][level] = min(base + avg_increment * level, battle_config.max_hp); /* some are still empty? then let's use the average increase */ } @@ -12166,7 +12196,13 @@ void status_read_job_db_sub(int idx, const char *name, config_setting_t *jdb) status->dbs->SP_table[idx][++level] = min(i32, battle_config.max_sp); } base = (level > 0 ? status->dbs->SP_table[idx][1] : 10); // Safe value if none are specified - avg_increment = (level > 1 ? (status->dbs->SP_table[idx][level] - base) / level : 1); + if (level > 2) { + if (level >= MAX_LEVEL + 1) + level = MAX_LEVEL; + avg_increment = (status->dbs->SP_table[idx][level] - base) / level; + } else { + avg_increment = 1; + } for ( ; level <= pc->max_level[idx][0]; level++ ) { status->dbs->SP_table[idx][level] = min(base + avg_increment * level, battle_config.max_sp); } -- cgit v1.2.3-70-g09d2