Skip to content

Commit

Permalink
Add do while(0) protection for macros
Browse files Browse the repository at this point in the history
Wrapping multi-line macros in do...while(0) statement prevents
potential dangling else problem.
  • Loading branch information
afcidk committed Jun 4, 2021
1 parent b6f86f3 commit bbbe307
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions hiredis.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,21 @@ typedef struct {
/**
* Helper macros to initialize options to their specified fields.
*/
#define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) \
(opts)->type = REDIS_CONN_TCP; \
(opts)->endpoint.tcp.ip = ip_; \
(opts)->endpoint.tcp.port = port_;

#define REDIS_OPTIONS_SET_UNIX(opts, path) \
(opts)->type = REDIS_CONN_UNIX; \
(opts)->endpoint.unix_socket = path;

#define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) \
(opts)->privdata = data; \
(opts)->free_privdata = dtor; \
#define REDIS_OPTIONS_SET_TCP(opts, ip_, port_) do { \
(opts)->type = REDIS_CONN_TCP; \
(opts)->endpoint.tcp.ip = ip_; \
(opts)->endpoint.tcp.port = port_; \
} while(0)

#define REDIS_OPTIONS_SET_UNIX(opts, path) do { \
(opts)->type = REDIS_CONN_UNIX; \
(opts)->endpoint.unix_socket = path; \
} while(0)

#define REDIS_OPTIONS_SET_PRIVDATA(opts, data, dtor) do { \
(opts)->privdata = data; \
(opts)->free_privdata = dtor; \
} while(0)

typedef struct redisContextFuncs {
void (*free_privctx)(void *);
Expand Down

0 comments on commit bbbe307

Please sign in to comment.