diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-04-13 14:25:22 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-04-13 14:25:22 +0000 |
commit | 74ae20b906cbdf6b0c17afa6d9911e5c3e58f161 (patch) | |
tree | 15a3bfde0e6b15e9c29d3e99a132a001eb6d17f5 | |
parent | b2392bc2641b957ab224a3b80fced60c46aa5b6f (diff) | |
download | hercules-74ae20b906cbdf6b0c17afa6d9911e5c3e58f161.tar.gz hercules-74ae20b906cbdf6b0c17afa6d9911e5c3e58f161.tar.bz2 hercules-74ae20b906cbdf6b0c17afa6d9911e5c3e58f161.tar.xz hercules-74ae20b906cbdf6b0c17afa6d9911e5c3e58f161.zip |
- Cleaned atcommand_param against overflows and also to make it standard C so it may compile with the Borland C.
- Modified Charcommand_stats to make it standard C as well.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6037 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | Changelog-Trunk.txt | 5 | ||||
-rw-r--r-- | src/map/atcommand.c | 43 | ||||
-rw-r--r-- | src/map/charcommand.c | 40 |
3 files changed, 58 insertions, 30 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 678701970..c30fa8656 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -3,6 +3,11 @@ Date Added AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
+
+2006/04/13
+ * atcommand_param and charcommand_stats to make them standard C (so it may
+ compile with the Borland C). Also cleaned atcommand_param against
+ overflows. [Skotlex]
2006/04/12
* Removed the noteleport mapflags from two juperos maps [MasterOfMuppets]
- added the nopenalty mapflag to hugel.gat
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index a6751cb85..e62c9a71a 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -4135,13 +4135,18 @@ int atcommand_param( const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
- int i, index, value = 0, new_value;
+ int index, value = 0, new_value, max;
const char* param[] = { "@str", "@agi", "@vit", "@int", "@dex", "@luk", NULL };
- short* status[] = {
- &sd->status.str, &sd->status.agi, &sd->status.vit,
- &sd->status.int_, &sd->status.dex, &sd->status.luk
- };
+ short* status[6];
+ //We don't use direct initialization because it isn't part of the C standard.
nullpo_retr(-1, sd);
+
+ status[0] = &sd->status.str;
+ status[1] = &sd->status.agi;
+ status[2] = &sd->status.vit;
+ status[3] = &sd->status.int_;
+ status[4] = &sd->status.dex;
+ status[5] = &sd->status.luk;
memset(atcmd_output, '\0', sizeof(atcmd_output));
@@ -4152,24 +4157,28 @@ int atcommand_param( }
index = -1;
- for (i = 0; param[i] != NULL; i++) {
- if (strcmpi(command, param[i]) == 0) {
- index = i;
+ for (index = 0; index < sizeof(param)/sizeof(param[0]); index++) {
+ if (strcmpi(command, param[index]) == 0)
break;
- }
}
- if (index < 0 || index > MAX_STATUS_TYPE) { // normaly impossible...
+ if (index == sizeof(param)/sizeof(param[0]) || index > MAX_STATUS_TYPE) {
+ // normaly impossible...
sprintf(atcmd_output, "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
clif_displaymessage(fd, atcmd_output);
return -1;
}
-
- new_value = (int)*status[index] + value;
- if (value > 0 && (value > pc_maxparameter(sd) || new_value > pc_maxparameter(sd))) // fix positiv overflow
- new_value = pc_maxparameter(sd);
- else if (value < 0 && (value < -(int)pc_maxparameter(sd) || new_value < 1)) // fix negativ overflow
- new_value = 1;
-
+ if (value >0) {
+ max = pc_maxparameter(sd);
+ if (*status[index] > max - value)
+ new_value = max;
+ else
+ new_value = *status[index] + value;
+ } else {
+ if (*status[index] <= -value)
+ new_value = 1;
+ else
+ new_value = *status[index] + value;
+ }
if (new_value != (int)*status[index]) {
*status[index] = new_value;
clif_updatestatus(sd, SP_STR + index);
diff --git a/src/map/charcommand.c b/src/map/charcommand.c index 3b9979e42..72a05288a 100644 --- a/src/map/charcommand.c +++ b/src/map/charcommand.c @@ -480,21 +480,35 @@ int charcommand_stats( const char* format;
int value;
} output_table[] = {
- { "Base Level - %d", pl_sd->status.base_level },
- { job_jobname, pl_sd->status.job_level },
- { "Hp - %d", pl_sd->status.hp },
- { "MaxHp - %d", pl_sd->status.max_hp },
- { "Sp - %d", pl_sd->status.sp },
- { "MaxSp - %d", pl_sd->status.max_sp },
- { "Str - %3d", pl_sd->status.str },
- { "Agi - %3d", pl_sd->status.agi },
- { "Vit - %3d", pl_sd->status.vit },
- { "Int - %3d", pl_sd->status.int_ },
- { "Dex - %3d", pl_sd->status.dex },
- { "Luk - %3d", pl_sd->status.luk },
- { "Zeny - %d", pl_sd->status.zeny },
+ { "Base Level - %d", 0 },
+ { job_jobname, 0 },
+ { "Hp - %d", 0 },
+ { "MaxHp - %d", 0 },
+ { "Sp - %d", 0 },
+ { "MaxSp - %d", 0 },
+ { "Str - %3d", 0 },
+ { "Agi - %3d", 0 },
+ { "Vit - %3d", 0 },
+ { "Int - %3d", 0 },
+ { "Dex - %3d", 0 },
+ { "Luk - %3d", 0 },
+ { "Zeny - %d", 0 },
{ NULL, 0 }
};
+ //direct array initialization with variables is not standard C compliant.
+ output_table[0].value = pl_sd->status.base_level;
+ output_table[1].value = pl_sd->status.job_level;
+ output_table[2].value = pl_sd->status.hp;
+ output_table[3].value = pl_sd->status.max_hp;
+ output_table[4].value = pl_sd->status.sp;
+ output_table[5].value = pl_sd->status.max_sp;
+ output_table[6].value = pl_sd->status.str;
+ output_table[7].value = pl_sd->status.agi;
+ output_table[8].value = pl_sd->status.vit;
+ output_table[9].value = pl_sd->status.int_;
+ output_table[10].value = pl_sd->status.dex;
+ output_table[11].value = pl_sd->status.luk;
+ output_table[12].value = pl_sd->status.zeny;
sprintf(job_jobname, "Job - %s %s", job_name(pl_sd->status.class_), "(level %d)");
sprintf(output, msg_table[53], pl_sd->status.name); // '%s' stats:
clif_displaymessage(fd, output);
|