summaryrefslogtreecommitdiff
path: root/src/common/showmsg.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/common/showmsg.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/common/showmsg.c')
-rw-r--r--src/common/showmsg.c111
1 files changed, 43 insertions, 68 deletions
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 9e0f63003..14342fe5e 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -16,33 +16,17 @@
#include "../../3rdparty/libconfig/libconfig.h"
#ifdef WIN32
- #include "../common/winapi.h"
-
- #ifdef DEBUGLOGMAP
- #define DEBUGLOGPATH "log\\map-server.log"
- #else
- #ifdef DEBUGLOGCHAR
- #define DEBUGLOGPATH "log\\char-server.log"
- #else
- #ifdef DEBUGLOGLOGIN
- #define DEBUGLOGPATH "log\\login-server.log"
- #endif
- #endif
- #endif
-#else
- #include <unistd.h>
-
- #ifdef DEBUGLOGMAP
- #define DEBUGLOGPATH "log/map-server.log"
- #else
- #ifdef DEBUGLOGCHAR
- #define DEBUGLOGPATH "log/char-server.log"
- #else
- #ifdef DEBUGLOGLOGIN
- #define DEBUGLOGPATH "log/login-server.log"
- #endif
- #endif
- #endif
+#include "../common/winapi.h"
+#else // not WIN32
+#include <unistd.h>
+#endif // WIN32
+
+#if defined(DEBUGLOGMAP)
+#define DEBUGLOGPATH "log"PATHSEP_STR"map-server.log"
+#elif defined(DEBUGLOGCHAR)
+#define DEBUGLOGPATH "log"PATHSEP_STR"char-server.log"
+#elif defined(DEBUGLOGLOGIN)
+#define DEBUGLOGPATH "log"PATHSEP_STR"login-server.log"
#endif
///////////////////////////////////////////////////////////////////////////////
@@ -61,41 +45,40 @@ int console_msg_log = 0;//[Ind] msg error logging
#define SBUF_SIZE 2054 // never put less that what's required for the debug message
-#define NEWBUF(buf) \
- struct { \
- char s_[SBUF_SIZE]; \
- StringBuf *d_; \
- char *v_; \
- int l_; \
- } buf ={"",NULL,NULL,0}; \
+#define NEWBUF(buf) \
+ struct { \
+ char s_[SBUF_SIZE]; \
+ StringBuf *d_; \
+ char *v_; \
+ int l_; \
+ } buf ={"",NULL,NULL,0}; \
//define NEWBUF
-#define BUFVPRINTF(buf,fmt,args) \
- buf.l_ = vsnprintf(buf.s_, SBUF_SIZE, fmt, args); \
- if( buf.l_ >= 0 && buf.l_ < SBUF_SIZE ) \
- {/* static buffer */ \
- buf.v_ = buf.s_; \
- } \
- else \
- {/* dynamic buffer */ \
- buf.d_ = StrBuf->Malloc(); \
- buf.l_ = StrBuf->Vprintf(buf.d_, fmt, args); \
- buf.v_ = StrBuf->Value(buf.d_); \
- ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", buf.l_+1);\
- } \
-//define BUFVPRINTF
-
-#define BUFVAL(buf) buf.v_
-#define BUFLEN(buf) buf.l_
-
-#define FREEBUF(buf) \
- if( buf.d_ ) \
- { \
- StrBuf->Free(buf.d_); \
- buf.d_ = NULL; \
- } \
- buf.v_ = NULL; \
-//define FREEBUF
+#define BUFVPRINTF(buf,fmt,args) do { \
+ (buf).l_ = vsnprintf((buf).s_, SBUF_SIZE, (fmt), args); \
+ if( (buf).l_ >= 0 && (buf).l_ < SBUF_SIZE ) \
+ {/* static buffer */ \
+ (buf).v_ = (buf).s_; \
+ } \
+ else \
+ {/* dynamic buffer */ \
+ (buf).d_ = StrBuf->Malloc(); \
+ (buf).l_ = StrBuf->Vprintf((buf).d_, (fmt), args); \
+ (buf).v_ = StrBuf->Value((buf).d_); \
+ ShowDebug("showmsg: dynamic buffer used, increase the static buffer size to %d or more.\n", (buf).l_+1); \
+ } \
+} while(0) //define BUFVPRINTF
+
+#define BUFVAL(buf) ((buf).v_)
+#define BUFLEN(buf) ((buf).l_)
+
+#define FREEBUF(buf) do {\
+ if( (buf).d_ ) { \
+ StrBuf->Free((buf).d_); \
+ (buf).d_ = NULL; \
+ } \
+ (buf).v_ = NULL; \
+} while(0) //define FREEBUF
///////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
@@ -666,14 +649,6 @@ int FPRINTF(FILE *file, const char *fmt, ...)
#endif// not _WIN32
-
-
-
-
-
-
-
-
char timestamp_format[20] = ""; //For displaying Timestamps
int _vShowMessage(enum msg_type flag, const char *string, va_list ap)