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/common/socket.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/common/socket.h') 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); -- cgit v1.2.3-70-g09d2