Commit 9e174e8f authored by Pei-Hsuan Hung's avatar Pei-Hsuan Hung Committed by Michael Grunder
Browse files

Add do while(0) protection for macros

Wrapping multi-line macros in do...while(0) statement prevents
potential dangling else problem.
parent 4ad99c69
...@@ -220,18 +220,21 @@ typedef struct { ...@@ -220,18 +220,21 @@ typedef struct {
/** /**
* Helper macros to initialize options to their specified fields. * Helper macros to initialize options to their specified fields.
*/ */
#define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) \ #define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) do { \
(opts)->type = REDIS_CONN_TCP; \ (opts)->type = REDIS_CONN_TCP; \
(opts)->endpoint.tcp.ip = ip_; \ (opts)->endpoint.tcp.ip = ip_; \
(opts)->endpoint.tcp.port = port_; (opts)->endpoint.tcp.port = port_; \
} while(0)
#define REDIS_OPTIONS_SET_UNIX(opts, path) \
(opts)->type = REDIS_CONN_UNIX; \ #define REDIS_OPTIONS_SET_UNIX(opts, path) do { \
(opts)->endpoint.unix_socket = path; (opts)->type = REDIS_CONN_UNIX; \
(opts)->endpoint.unix_socket = path; \
#define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) \ } while(0)
(opts)->privdata = data; \
(opts)->free_privdata = dtor; \ #define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) do { \
(opts)->privdata = data; \
(opts)->free_privdata = dtor; \
} while(0)
typedef struct redisContextFuncs { typedef struct redisContextFuncs {
void (*free_privctx)(void *); void (*free_privctx)(void *);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment