summaryrefslogtreecommitdiff
path: root/src/common/socket.h
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/socket.h
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/socket.h')
-rw-r--r--src/common/socket.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/common/socket.h b/src/common/socket.h
index 923fa2515..02817f653 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -24,18 +24,18 @@ struct HPluginData;
// socket I/O macros
#define RFIFOHEAD(fd)
-#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo(fd, size); }while(0)
+#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo((fd), (size)); }while(0)
#define RFIFOP(fd,pos) (session[fd]->rdata + session[fd]->rdata_pos + (pos))
#define WFIFOP(fd,pos) (session[fd]->wdata + session[fd]->wdata_size + (pos))
-#define RFIFOB(fd,pos) (*(uint8*)RFIFOP(fd,pos))
-#define WFIFOB(fd,pos) (*(uint8*)WFIFOP(fd,pos))
-#define RFIFOW(fd,pos) (*(uint16*)RFIFOP(fd,pos))
-#define WFIFOW(fd,pos) (*(uint16*)WFIFOP(fd,pos))
-#define RFIFOL(fd,pos) (*(uint32*)RFIFOP(fd,pos))
-#define WFIFOL(fd,pos) (*(uint32*)WFIFOP(fd,pos))
-#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP(fd,pos))
-#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP(fd,pos))
+#define RFIFOB(fd,pos) (*(uint8*)RFIFOP((fd),(pos)))
+#define WFIFOB(fd,pos) (*(uint8*)WFIFOP((fd),(pos)))
+#define RFIFOW(fd,pos) (*(uint16*)RFIFOP((fd),(pos)))
+#define WFIFOW(fd,pos) (*(uint16*)WFIFOP((fd),(pos)))
+#define RFIFOL(fd,pos) (*(uint32*)RFIFOP((fd),(pos)))
+#define WFIFOL(fd,pos) (*(uint32*)WFIFOP((fd),(pos)))
+#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP((fd),(pos)))
+#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP((fd),(pos)))
#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size)
#define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size)
@@ -146,8 +146,9 @@ void set_defaultparse(ParseFunc defaultparse);
uint32 host2ip(const char* hostname);
const char* ip2str(uint32 ip, char ip_str[16]);
uint32 str2ip(const char* ip_str);
+// Note: purposely returns four comma-separated arguments
#define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF
-#define MAKEIP(a,b,c,d) (uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) )
+#define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) ))
uint16 ntows(uint16 netshort);
int socket_getips(uint32* ips, int max);