summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaruna <haru@dotalux.com>2015-08-17 17:37:55 +0200
committerHaruna <haru@dotalux.com>2015-08-17 17:37:55 +0200
commit2f2e04c172a6fde55b1f7f7cf79f66d56894e86f (patch)
treeb00903a5250712c78fef9053590d60857a473e6c
parente79efdeee4dd7d2d1632e1703500f9785f962f8f (diff)
parentc31fa9cd48352db8fde5ef91f38bef8ad9507431 (diff)
downloadhercules-2f2e04c172a6fde55b1f7f7cf79f66d56894e86f.tar.gz
hercules-2f2e04c172a6fde55b1f7f7cf79f66d56894e86f.tar.bz2
hercules-2f2e04c172a6fde55b1f7f7cf79f66d56894e86f.tar.xz
hercules-2f2e04c172a6fde55b1f7f7cf79f66d56894e86f.zip
Merge pull request #654 from 4144/memfixes
Different memory corruption fixes
-rwxr-xr-xconfigure2
-rw-r--r--src/common/malloc.c3
-rw-r--r--src/map/status.c48
3 files changed, 45 insertions, 8 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/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;
}
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);
}