Safer macro parenthesization and do/while use

remotes/origin/master-1.1.x
pilcrow 14 years ago committed by Victor Julien
parent bbd04fde30
commit ed69eeab14

@ -135,30 +135,30 @@ typedef struct Address_ {
/* Set the TCP ports into the Ports of the Packet.
* Make sure p->tcph is initialized and validated. */
#define SET_TCP_SRC_PORT(pkt, prt) do { \
SET_PORT(TCP_GET_SRC_PORT((pkt)), *prt); \
SET_PORT(TCP_GET_SRC_PORT((pkt)), *(prt)); \
} while (0)
#define SET_TCP_DST_PORT(pkt, prt) do { \
SET_PORT(TCP_GET_DST_PORT((pkt)), *prt); \
SET_PORT(TCP_GET_DST_PORT((pkt)), *(prt)); \
} while (0)
/* Set the UDP ports into the Ports of the Packet.
* Make sure p->udph is initialized and validated. */
#define SET_UDP_SRC_PORT(pkt, prt) do { \
SET_PORT(UDP_GET_SRC_PORT((pkt)), *prt); \
SET_PORT(UDP_GET_SRC_PORT((pkt)), *(prt)); \
} while (0)
#define SET_UDP_DST_PORT(pkt, prt) do { \
SET_PORT(UDP_GET_DST_PORT((pkt)), *prt); \
SET_PORT(UDP_GET_DST_PORT((pkt)), *(prt)); \
} while (0)
/* Set the SCTP ports into the Ports of the Packet.
* Make sure p->sctph is initialized and validated. */
#define SET_SCTP_SRC_PORT(pkt, prt) do { \
SET_PORT(SCTP_GET_SRC_PORT((pkt)), *prt); \
SET_PORT(SCTP_GET_SRC_PORT((pkt)), *(prt)); \
} while (0)
#define SET_SCTP_DST_PORT(pkt, prt) do { \
SET_PORT(SCTP_GET_DST_PORT((pkt)), *prt); \
SET_PORT(SCTP_GET_DST_PORT((pkt)), *(prt)); \
} while (0)
@ -175,18 +175,18 @@ typedef struct Address_ {
#define GET_PKT_LEN(p) ((p)->pktlen)
#define GET_PKT_DATA(p) ((((p)->ext_pkt) == NULL ) ? (p)->pkt : (p)->ext_pkt)
#define GET_PKT_DIRECT_DATA(p) (p)->pkt
#define GET_PKT_DIRECT_MAX_SIZE(p) default_packet_size
#define GET_PKT_DIRECT_DATA(p) ((p)->pkt)
#define GET_PKT_DIRECT_MAX_SIZE(p) (default_packet_size)
#define SET_PKT_LEN(p, len) do { \
(p)->pktlen = len; \
(p)->pktlen = (len); \
} while (0)
/* Port is just a uint16_t */
typedef uint16_t Port;
#define SET_PORT(v, p) ((p) = (v))
#define COPY_PORT(a,b) (b) = (a)
#define COPY_PORT(a,b) ((b) = (a))
#define CMP_ADDR(a1, a2) \
(((a1)->addr_data32[3] == (a2)->addr_data32[3] && \
@ -194,11 +194,11 @@ typedef uint16_t Port;
(a1)->addr_data32[1] == (a2)->addr_data32[1] && \
(a1)->addr_data32[0] == (a2)->addr_data32[0]))
#define CMP_PORT(p1, p2) \
((p1 == p2))
((p1) == (p2))
/*Given a packet pkt offset to the start of the ip header in a packet
*We determine the ip version. */
#define IP_GET_RAW_VER(pkt) (((pkt[0] & 0xf0) >> 4))
#define IP_GET_RAW_VER(pkt) ((((pkt)[0] & 0xf0) >> 4))
#define PKT_IS_IPV4(p) (((p)->ip4h != NULL))
#define PKT_IS_IPV6(p) (((p)->ip6h != NULL))
@ -213,7 +213,7 @@ typedef uint16_t Port;
/* Retrieve proto regardless of IP version */
#define IP_GET_IPPROTO(p) \
(PKT_IS_IPV4(p)? IPV4_GET_IPPROTO(p) : (PKT_IS_IPV6(p)? IPV6_GET_NH(p) : 0))
(PKT_IS_IPV4((p))? IPV4_GET_IPPROTO((p)) : (PKT_IS_IPV6((p))? IPV6_GET_NH((p)) : 0))
/* structure to store the sids/gids/etc the detection engine
* found in this packet */
@ -459,11 +459,11 @@ typedef struct Packet_
#endif
} Packet;
#define DEFAULT_PACKET_SIZE 1500 + ETHERNET_HEADER_LEN
#define DEFAULT_PACKET_SIZE (1500 + ETHERNET_HEADER_LEN)
/* storage: maximum ip packet size + link header */
#define MAX_PAYLOAD_SIZE IPV6_HEADER_LEN + 65536 + 28
#define MAX_PAYLOAD_SIZE (IPV6_HEADER_LEN + 65536 + 28)
intmax_t default_packet_size;
#define SIZE_OF_PACKET default_packet_size + sizeof(Packet)
#define SIZE_OF_PACKET (default_packet_size + sizeof(Packet))
typedef struct PacketQueue_ {
Packet *top;

@ -65,7 +65,7 @@
/**
* Maximum allowed timeout, 24 hours.
*/
#define TIMEOUT_MAX 60 * 60 * 24
#define TIMEOUT_MAX (60 * 60 * 24)
/**
* Minimum allowed timeout, 1 second.

@ -69,7 +69,7 @@
//#define FLOW_DEFAULT_HASHSIZE 262144
#define FLOW_DEFAULT_HASHSIZE 65536
//#define FLOW_DEFAULT_MEMCAP 128 * 1024 * 1024 /* 128 MB */
#define FLOW_DEFAULT_MEMCAP 32 * 1024 * 1024 /* 32 MB */
#define FLOW_DEFAULT_MEMCAP (32 * 1024 * 1024) /* 32 MB */
#define FLOW_DEFAULT_PREALLOC 10000

@ -83,7 +83,7 @@
*/
#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
#define _Q_INVALIDATE(a) (a) = ((void *)-1)
#define _Q_INVALIDATE(a) ((a) = ((void *)-1))
#else
#define _Q_INVALIDATE(a)
#endif

@ -69,8 +69,8 @@
#define STREAMTCP_DEFAULT_SESSIONS 262144
#define STREAMTCP_DEFAULT_PREALLOC 32768
#define STREAMTCP_DEFAULT_MEMCAP 32 * 1024 * 1024 /* 32mb */
#define STREAMTCP_DEFAULT_REASSEMBLY_MEMCAP 64 * 1024 * 1024 /* 64mb */
#define STREAMTCP_DEFAULT_MEMCAP (32 * 1024 * 1024) /* 32mb */
#define STREAMTCP_DEFAULT_REASSEMBLY_MEMCAP (64 * 1024 * 1024) /* 64mb */
#define STREAMTCP_DEFAULT_TOSERVER_CHUNK_SIZE 2560
#define STREAMTCP_DEFAULT_TOCLIENT_CHUNK_SIZE 2560

@ -52,10 +52,14 @@ enum {
};
/** You can use this macros to set/check if we have real drop capabilities */
#define SET_ENGINE_MODE_IPS(engine_mode) (engine_mode = ENGINE_MODE_IPS);
#define SET_ENGINE_MODE_IDS(engine_mode) (engine_mode = ENGINE_MODE_IDS);
#define IS_ENGINE_MODE_IPS(engine_mode) (engine_mode == ENGINE_MODE_IPS)
#define IS_ENGINE_MODE_IDS(engine_mode) (engine_mode == ENGINE_MODE_IDS)
#define SET_ENGINE_MODE_IPS(engine_mode) do { \
(engine_mode) = ENGINE_MODE_IPS; \
} while (0)
#define SET_ENGINE_MODE_IDS(engine_mode) do { \
(engine_mode) = ENGINE_MODE_IDS; \
} while (0)
#define IS_ENGINE_MODE_IPS(engine_mode) ((engine_mode) == ENGINE_MODE_IPS)
#define IS_ENGINE_MODE_IDS(engine_mode) ((engine_mode) == ENGINE_MODE_IDS)
/* queue's between various other threads
* XXX move to the TmQueue structure later

@ -55,9 +55,9 @@
#include <mach/mach_init.h>
#include <mach/thread_policy.h>
#define cpu_set_t thread_affinity_policy_data_t
#define CPU_SET(cpu_id, new_mask) (*(new_mask)).affinity_tag = (cpu_id + 1)
#define CPU_ISSET(cpu_id, new_mask) ((*(new_mask)).affinity_tag == (cpu_id + 1))
#define CPU_ZERO(new_mask) (*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL
#define CPU_SET(cpu_id, new_mask) ((*(new_mask)).affinity_tag = ((cpu_id) + 1))
#define CPU_ISSET(cpu_id, new_mask) (((*(new_mask)).affinity_tag == ((cpu_id) + 1)))
#define CPU_ZERO(new_mask) ((*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL)
#endif /* OS_FREEBSD */
/* prototypes */

@ -4718,8 +4718,9 @@ static const char *sc_cuda_test_kernel_32_bit =
int SCCudaTest02(void)
{
#define ALIGN_UP(offset, alignment) \
(offset) = ((offset) + (alignment) - 1) & ~((alignment) - 1)
#define ALIGN_UP(offset, alignment) do { \
(offset) = ((offset) + (alignment) - 1) & ~((alignment) - 1); \
} while (0)
#define N 256
CUcontext context;
CUmodule module;

@ -49,20 +49,20 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
extern size_t global_mem; \
extern uint8_t print_mem_flag; \
\
ptrmem = malloc(a); \
if (ptrmem == NULL && a > 0) { \
ptrmem = malloc((a)); \
if (ptrmem == NULL && (a) > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
} \
\
global_mem += a; \
global_mem += (a); \
if (print_mem_flag == 1) \
SCLogInfo("SCMalloc return at %p of size %"PRIuMAX, \
ptrmem, (uintmax_t)a); \
ptrmem, (uintmax_t)(a)); \
\
(void*)ptrmem; \
})
@ -72,20 +72,20 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
extern size_t global_mem; \
extern uint8_t print_mem_flag; \
\
ptrmem = realloc(x, a); \
if (ptrmem == NULL && a > 0) { \
ptrmem = realloc((x), (a)); \
if (ptrmem == NULL && (a) > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
} \
\
global_mem += a; \
global_mem += (a); \
if (print_mem_flag == 1) \
SCLogInfo("SCRealloc return at %p (old:%p) of size %"PRIuMAX, \
ptrmem, x, (uintmax_t)a); \
ptrmem, (x), (uintmax_t)(a)); \
\
(void*)ptrmem; \
})
@ -95,8 +95,8 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
extern size_t global_mem; \
extern uint8_t print_mem_flag; \
\
ptrmem = calloc(nm, a); \
if (ptrmem == NULL && a > 0) { \
ptrmem = calloc((nm), (a)); \
if (ptrmem == NULL && (a) > 0) { \
SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
@ -105,10 +105,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
} \
} \
\
global_mem += a*nm; \
global_mem += (a)*(nm); \
if (print_mem_flag == 1) \
SCLogInfo("SCCalloc return at %p of size %"PRIuMAX" nm %"PRIuMAX, \
ptrmem, (uintmax_t)a, (uintmax_t)nm); \
SCLogInfo("SCCalloc return at %p of size %"PRIuMAX" (nm) %"PRIuMAX, \
ptrmem, (uintmax_t)(a), (uintmax_t)(nm)); \
\
(void*)ptrmem; \
})
@ -117,10 +117,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
char *ptrmem = NULL; \
extern size_t global_mem; \
extern uint8_t print_mem_flag; \
size_t len = strlen((a)); \
\
ptrmem = strdup(a); \
ptrmem = strdup((a)); \
if (ptrmem == NULL) { \
size_t len = strlen(a); \
SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)len); \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
@ -140,20 +140,20 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
#define SCFree(a) ({ \
extern uint8_t print_mem_flag; \
if (print_mem_flag == 1) \
SCLogInfo("SCFree at %p", a); \
free(a); \
SCLogInfo("SCFree at %p", (a)); \
free((a)); \
})
#else /* DBG_MEM_ALLOC */
#else /* !DBG_MEM_ALLOC */
#define SCMalloc(a) ({ \
void *ptrmem = NULL; \
\
ptrmem = malloc(a); \
ptrmem = malloc((a)); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -164,11 +164,11 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
#define SCRealloc(x, a) ({ \
void *ptrmem = NULL; \
\
ptrmem = realloc(x, a); \
ptrmem = realloc((x), (a)); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -179,11 +179,11 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
#define SCCalloc(nm, a) ({ \
void *ptrmem = NULL; \
\
ptrmem = calloc(nm, a); \
ptrmem = calloc((nm), (a)); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -194,10 +194,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
#define SCStrdup(a) ({ \
char *ptrmem = NULL; \
\
ptrmem = strdup(a); \
ptrmem = strdup((a)); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
size_t len = strlen(a); \
size_t len = strlen((a)); \
SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)len); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
@ -217,7 +217,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
if (posix_memalign(&ptrmem, (b), (a)) != 0) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCMallocAligned(posix_memalign) failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)a, (uintmax_t)b); \
"to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)(a), (uintmax_t)(b)); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
@ -226,7 +226,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
})
#define SCFree(a) ({ \
free(a); \
free((a)); \
})
/** \brief Free aligned memory
@ -236,7 +236,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
* _mm_free.
*/
#define SCFreeAligned(a) ({ \
free(a); \
free((a)); \
})

@ -65,7 +65,7 @@ void SCACGfbsPrintSearchStats(MpmThreadCtx *mpm_thread_ctx);
void SCACGfbsRegisterTests(void);
/* a placeholder to denote a failure transition in the goto table */
#define SC_AC_GFBS_FAIL -1
#define SC_AC_GFBS_FAIL (-1)
/* size of the hash table used to speed up pattern insertions initially */
#define INIT_HASH_SIZE 65536

@ -72,7 +72,7 @@ void SCACPrintSearchStats(MpmThreadCtx *mpm_thread_ctx);
void SCACRegisterTests(void);
/* a placeholder to denote a failure transition in the goto table */
#define SC_AC_FAIL -1
#define SC_AC_FAIL (-1)
/* size of the hash table used to speed up pattern insertions initially */
#define INIT_HASH_SIZE 65536

@ -1451,7 +1451,9 @@ static int B2gCudaMpmStreamDataInit(B2gCudaMpmThreadCtxData *tctx, MpmCudaConf *
goto error;
}
#define ALIGN_UP(offset, alignment) (offset) = ((offset) + (alignment) - 1) & ~((alignment) - 1)
#define ALIGN_UP(offset, alignment) do { \
(offset) = ((offset) + (alignment) - 1) & ~((alignment) - 1); \
} while (0)
int offset = 0;

Loading…
Cancel
Save