summaryrefslogtreecommitdiff
path: root/src/map/status.c
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-03-07 19:59:57 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-03-07 19:59:57 +0000
commit21c0f0116e732e12e2e0c46c6658396c0182bb85 (patch)
tree3ddd6488419226a22124538b94d46efdc9b35e9d /src/map/status.c
parenta76136af59c63092eae837abf9d9a03405334494 (diff)
downloadhercules-21c0f0116e732e12e2e0c46c6658396c0182bb85.tar.gz
hercules-21c0f0116e732e12e2e0c46c6658396c0182bb85.tar.bz2
hercules-21c0f0116e732e12e2e0c46c6658396c0182bb85.tar.xz
hercules-21c0f0116e732e12e2e0c46c6658396c0182bb85.zip
- Some overflow protections on calculation of max hp. Now when max hp becomes negative, it is bumped to the server's max_hp setting (it is assumed there was an overflow)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@5493 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/status.c')
-rw-r--r--src/map/status.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/map/status.c b/src/map/status.c
index 3e0c844f5..23a4db4a8 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <memory.h>
#include <string.h>
+#include <limits.h>
#include "pc.h"
#include "map.h"
@@ -1374,11 +1375,14 @@ int status_calc_pc(struct map_session_data* sd,int first)
sd->status.max_hp = sd->status.max_hp * sd->hprate/100;
if(battle_config.hp_rate != 100)
sd->status.max_hp = sd->status.max_hp * battle_config.hp_rate/100;
-
- if(sd->status.max_hp > battle_config.max_hp)
+
+ if (sd->status.max_hp < 0) //HP overflow??
+ sd->status.max_hp = battle_config.max_hp;
+ else if(sd->status.max_hp > battle_config.max_hp)
sd->status.max_hp = battle_config.max_hp;
- else if(sd->status.max_hp <= 0)
+ else if(sd->status.max_hp == 0)
sd->status.max_hp = 1;
+
if(sd->status.hp>sd->status.max_hp)
sd->status.hp=sd->status.max_hp;
@@ -5623,7 +5627,8 @@ int status_change_clear_debuffs (struct block_list *bl)
static int status_calc_sigma(void)
{
- int i,j,k;
+ int i,j;
+ unsigned int k;
for(i=0;i<MAX_PC_CLASS;i++) {
memset(hp_sigma_val[i],0,sizeof(hp_sigma_val[i]));
@@ -5631,7 +5636,11 @@ static int status_calc_sigma(void)
k += hp_coefficient[i]*j + 50;
k -= k%100;
hp_sigma_val[i][j-1] = k;
+ if (k >= INT_MAX)
+ break; //Overflow protection. [Skotlex]
}
+ for(;j<=MAX_LEVEL;j++)
+ hp_sigma_val[i][j-1] = INT_MAX;
}
return 0;
}