summaryrefslogtreecommitdiff
path: root/src/map/atcommand.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-11-18 08:53:22 +0100
committerHaru <haru@dotalux.com>2013-11-19 03:41:30 +0100
commit12dce46d611d6ea7c772174ebbd555fa10fead99 (patch)
tree8f953e4166750c2ec1cbd1df89717b8d5dc8f455 /src/map/atcommand.c
parent51cbaf27c96e874850588ddcfa13b656db45bb2e (diff)
downloadhercules-12dce46d611d6ea7c772174ebbd555fa10fead99.tar.gz
hercules-12dce46d611d6ea7c772174ebbd555fa10fead99.tar.bz2
hercules-12dce46d611d6ea7c772174ebbd555fa10fead99.tar.xz
hercules-12dce46d611d6ea7c772174ebbd555fa10fead99.zip
Sanitized and improved several macros through the code
- Sanitized all potentially unsafe macros (related eA:15259) - Improved some function-like macros to evaluate their argument only once and keep it in a temporary variable. This improves performance in the damage calculation related code. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r--src/map/atcommand.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 4a471fe5d..3b06140d4 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -164,38 +164,32 @@ ACMD(send)
clif->message(fd, msg_txt(i));
return false;
}
-
-#define PARSE_ERROR(error,p) \
-{\
-clif->message(fd, (error));\
-sprintf(atcmd_output, ">%s", (p));\
-clif->message(fd, atcmd_output);\
-}
- //define PARSE_ERROR
-
-#define CHECK_EOS(p) \
-if(*(p) == 0){\
-clif->message(fd, "Unexpected end of string");\
-return false;\
-}
- //define CHECK_EOS
-
-#define SKIP_VALUE(p) \
-{\
-while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
-while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
-}
- //define SKIP_VALUE
-
-#define GET_VALUE(p,num) \
-{\
-if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
-PARSE_ERROR("Invalid number in:",(p));\
-return false;\
-}\
-}
- //define GET_VALUE
-
+
+#define PARSE_ERROR(error,p) do {\
+ clif->message(fd, (error));\
+ sprintf(atcmd_output, ">%s", (p));\
+ clif->message(fd, atcmd_output);\
+} while(0) //define PARSE_ERROR
+
+#define CHECK_EOS(p) do { \
+ if(*(p) == 0){ \
+ clif->message(fd, "Unexpected end of string");\
+ return false;\
+ } \
+} while(0) //define CHECK_EOS
+
+#define SKIP_VALUE(p) do { \
+ while(*(p) && !ISSPACE(*(p))) ++(p); /* non-space */\
+ while(*(p) && ISSPACE(*(p))) ++(p); /* space */\
+} while(0) //define SKIP_VALUE
+
+#define GET_VALUE(p,num) do { \
+ if(sscanf((p), "x%lx", &(num)) < 1 && sscanf((p), "%ld ", &(num)) < 1){\
+ PARSE_ERROR("Invalid number in:",(p));\
+ return false;\
+ }\
+} while(0) //define GET_VALUE
+
if (type > 0 && type < MAX_PACKET_DB) {
if(len)
@@ -8585,10 +8579,11 @@ ACMD(unloadnpcfile) {
return true;
}
ACMD(cart) {
-#define MC_CART_MDFY(x,idx) \
-sd->status.skill[idx].id = x?MC_PUSHCART:0; \
-sd->status.skill[idx].lv = x?1:0; \
-sd->status.skill[idx].flag = x?1:0;
+#define MC_CART_MDFY(x,idx) do { \
+ sd->status.skill[idx].id = (x)?MC_PUSHCART:0; \
+ sd->status.skill[idx].lv = (x)?1:0; \
+ sd->status.skill[idx].flag = (x)?1:0; \
+} while(0)
int val = atoi(message);
bool need_skill = pc->checkskill(sd, MC_PUSHCART) ? false : true;
@@ -9616,6 +9611,8 @@ void atcommand_basecommands(void) {
return;
}
+#undef ACMD_DEF
+#undef ACMD_DEF2
bool atcommand_add(char *name,AtCommandFunc func, bool replace) {
AtCommandInfo* cmd;