From 12dce46d611d6ea7c772174ebbd555fa10fead99 Mon Sep 17 00:00:00 2001 From: Haru Date: Mon, 18 Nov 2013 08:53:22 +0100 Subject: 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 --- src/char/char.c | 2 +- src/char/char.h | 2 +- src/char/inter.h | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/char') diff --git a/src/char/char.c b/src/char/char.c index f1b95474e..a1c6f73b1 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -3933,7 +3933,7 @@ int parse_char(int fd) while( RFIFOREST(fd) >= 2 ) { //For use in packets that depend on an sd being present [Skotlex] - #define FIFOSD_CHECK(rest) { if(RFIFOREST(fd) < rest) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,rest); return 0; } } + #define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0) if( HPM->packetsc[hpParse_Char] ) { if( (i = HPM->parse_packets(fd,hpParse_Char)) ) { diff --git a/src/char/char.h b/src/char/char.h index c7a387645..c6aa1b66d 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -48,7 +48,7 @@ DBMap* online_char_db; // int account_id -> struct online_char_data* #define MAX_MAP_SERVERS 2 -#define DEFAULT_AUTOSAVE_INTERVAL 300*1000 +#define DEFAULT_AUTOSAVE_INTERVAL (300*1000) enum { TABLE_INVENTORY, diff --git a/src/char/inter.h b/src/char/inter.h index 88501c9a0..9b958dc72 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -30,13 +30,12 @@ int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type uint64 inter_chk_lastuid(int8 flag, uint64 value); #ifdef NSI_UNIQUE_ID - #define updateLastUid(val_) inter_chk_lastuid(1, val_) - #define dbUpdateUid(handler_)\ - { \ + #define updateLastUid(val_) inter_chk_lastuid(1, (val_)) + #define dbUpdateUid(handler_) do { \ uint64 unique_id_ = inter_chk_lastuid(0, 0); \ - if (unique_id_ && SQL_ERROR == SQL->Query(handler_, "UPDATE `%s` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", interreg_db, unique_id_)) \ + if (unique_id_ && SQL_ERROR == SQL->Query((handler_), "UPDATE `%s` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", interreg_db, unique_id_)) \ Sql_ShowDebug(handler_);\ - } + } while(0) #else #define dbUpdateUid(handler_) #define updateLastUid(val_) -- cgit v1.2.3-60-g2f50