diff options
author | Paradox924X <Paradox924X@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-10-28 05:45:34 +0000 |
---|---|---|
committer | Paradox924X <Paradox924X@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-10-28 05:45:34 +0000 |
commit | b8930b01796ed45000a6929b56d1f3a92b8d40c0 (patch) | |
tree | 07a45283a4907f57cd8564ae9bb5c9ce2cf1f676 /src/map/atcommand.c | |
parent | 3a1fe6e9998f20f4daf5b1eb2aa5e515a81e3bd8 (diff) | |
download | hercules-b8930b01796ed45000a6929b56d1f3a92b8d40c0.tar.gz hercules-b8930b01796ed45000a6929b56d1f3a92b8d40c0.tar.bz2 hercules-b8930b01796ed45000a6929b56d1f3a92b8d40c0.tar.xz hercules-b8930b01796ed45000a6929b56d1f3a92b8d40c0.zip |
Fixed all overflow checks and made the code a bit cleaner from r13322.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13331 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 260288690..e37c712af 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -1505,7 +1505,7 @@ int atcommand_heal(const int fd, struct map_session_data* sd, const char* comman sscanf(message, "%d %d", &hp, &sp); if ( ( hp == 0 && sp == 0 ) - || ( hp > 2147483647 || sp > 2147483647 ) ) { // Prevent overflow. [Paradox924X] + || ( hp > INT_MAX && sp > INT_MAX ) ) { // Prevent overflow. [Paradox924X] if (!status_percent_heal(&sd->bl, 100, 100)) clif_displaymessage(fd, msg_txt(157)); // HP and SP have already been recovered. else @@ -1513,14 +1513,40 @@ int atcommand_heal(const int fd, struct map_session_data* sd, const char* comman return 0; } - if ( hp < -2147483647 || sp < -2147483647 ) { // Prevent overflow. [Paradox924X] - status_damage(NULL, &sd->bl, 2147483647, 2147483647, 0, 0); - clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, 2147483647, 0 , 4, 0); + // Prevent overflow. [Paradox924X] + if ( hp < -INT_MAX && sp < -INT_MAX ) { + status_damage(NULL, &sd->bl, INT_MAX, INT_MAX, 0, 0); + clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, INT_MAX, 0, 4, 0); clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified. return 0; } - if(hp > 0 && sp >= 0) { + // Prevent overflow. [Paradox924X] + if ( hp > INT_MAX ) { + if (!status_percent_heal(&sd->bl, 100, 0)) + clif_displaymessage(fd, msg_txt(157)); // HP and SP have already been recovered. + else + clif_displaymessage(fd, msg_txt(17)); // HP, SP recovered. + return 0; + } else if ( hp < -INT_MAX ) { + status_damage(NULL, &sd->bl, INT_MAX, 0, 0, 0); + clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, INT_MAX, 0, 4, 0); + clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified. + return 0; + } + + // Prevent overflow. [Paradox924X] + if ( sp > INT_MAX ) { + status_heal(&sd->bl, 0, INT_MAX, 0); + clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified. + return 0; + } else if ( sp < -INT_MAX ) { + status_damage(NULL, &sd->bl, 0, INT_MAX, 0, 0); + clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified. + return 0; + } + + if ( hp > 0 && sp >= 0 ) { if(!status_heal(&sd->bl, hp, sp, 0)) clif_displaymessage(fd, msg_txt(157)); // HP and SP are already with the good value. else @@ -1528,24 +1554,24 @@ int atcommand_heal(const int fd, struct map_session_data* sd, const char* comman return 0; } - if(hp < 0 && sp <= 0) { + if ( hp < 0 && sp <= 0 ) { status_damage(NULL, &sd->bl, -hp, -sp, 0, 0); - clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0 , 4, 0); + clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0); clif_displaymessage(fd, msg_txt(156)); // HP or/and SP modified. return 0; } //Opposing signs. - if (hp) { + if ( hp ) { if (hp > 0) status_heal(&sd->bl, hp, 0, 0); else { status_damage(NULL, &sd->bl, -hp, 0, 0, 0); - clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0 , 4, 0); + clif_damage(&sd->bl,&sd->bl, gettick(), 0, 0, -hp, 0, 4, 0); } } - if (sp) { + if ( sp ) { if (sp > 0) status_heal(&sd->bl, 0, sp, 0); else |