summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPei-Hsuan Hung <afcidk@gmail.com>2021-06-04 11:33:39 +0800
committerMichael Grunder <michael.grunder@gmail.com>2022-08-30 11:41:59 -0700
commit9e174e8f7d134fea69b0afd7e36443009b83badf (patch)
treec88b3b1804f32adbe8b176a3cc9c0f3469433d0f
parent4ad99c69a21edb80f960877fccf9f9e13073ef30 (diff)
Add do while(0) protection for macros
Wrapping multi-line macros in do...while(0) statement prevents potential dangling else problem.
-rw-r--r--hiredis.h27
1 files changed, 15 insertions, 12 deletions
diff --git a/hiredis.h b/hiredis.h
index b378128..7e2a84d 100644
--- a/hiredis.h
+++ b/hiredis.h
@@ -220,18 +220,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 *);