[openib-general] [PATCH] SDP headers using unsafe macros
Michael S. Tsirkin
mst at mellanox.co.il
Thu Feb 17 07:46:43 PST 2005
Some SDP hdeaders defines unsafe macros, which may be
dangerous to use, e.g. inside an if or while statement.
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
Index: sdp_proto.h
===================================================================
--- sdp_proto.h (revision 1810)
+++ sdp_proto.h (working copy)
@@ -585,15 +585,16 @@
#define SDP_EXPECT(expr)
#define SDP_CHECK_NULL(value, result)
#else
-#define SDP_EXPECT(expr) \
-{ \
- if (!(expr)) { \
- sdp_dbg_err("EXCEPT: Internal error check <%s> failed.", #expr); \
- } \
-} /* SDP_EXPECT */
+#define SDP_EXPECT(expr) \
+do { \
+ if (!(expr)) { \
+ sdp_dbg_err("EXCEPT: Internal error check <%s> failed.", \
+ #expr); \
+ } \
+} while (0) /* SDP_EXPECT */
#define SDP_CHECK_NULL(value, result) \
- if (NULL == (value)) return (result);
+ do { if (NULL == (value)) return (result); } while (0)
#endif
/* --------------------------------------------------------------------- */
/* Inline functions. */
Index: sdp_conn.h
===================================================================
--- sdp_conn.h (revision 1810)
+++ sdp_conn.h (working copy)
@@ -102,7 +102,7 @@
* transition one of the disconnect pending states to disconnect send
*/
#define SDP_ST_PEND_2_SEND(conn) \
- (conn)->state = ((conn)->state + 0x0100) & ~SDP_ST_MASK_DIS_PEND;
+ ((conn)->state = ((conn)->state + 0x0100) & ~SDP_ST_MASK_DIS_PEND)
/*
* internal connection structure
*/
@@ -130,14 +130,14 @@
* connection handle within a socket.
*/
#define SDP_GET_CONN(sk) \
- *((struct sdp_opt **)&(sk)->sk_protinfo)
+ (*((struct sdp_opt **)&(sk)->sk_protinfo))
#define SDP_SET_CONN(sk, conn) \
- *((struct sdp_opt **)&(sk)->sk_protinfo) = (conn)
+ (*((struct sdp_opt **)&(sk)->sk_protinfo) = (conn))
#define SDP_CONN_SET_ERR(conn, val) \
- (conn)->error = (conn)->sk->sk_err = (val)
+ ((conn)->error = (conn)->sk->sk_err = (val))
#define SDP_CONN_GET_ERR(conn) \
- (conn)->error
+ ((conn)->error)
/* --------------------------------------------------------------------- */
/* state transition information recording */
/* --------------------------------------------------------------------- */
@@ -153,7 +153,7 @@
}; /* struct sdp_conn_state */
#define SDP_CONN_ST_SET(conn, val) \
-{ \
+do { \
(conn)->state = (val); \
if (SDP_CONN_STATE_MAX > (conn)->state_rec.value) { \
(conn)->state_rec.state[(conn)->state_rec.value] = (val); \
@@ -161,10 +161,10 @@
(conn)->state_rec.line[(conn)->state_rec.value] = __LINE__; \
(conn)->state_rec.value++; \
} \
-}
+} while(0)
#define SDP_CONN_ST_INIT(conn) \
-{ \
+do { \
(conn)->state = SDP_CONN_ST_INVALID; \
for ((conn)->state_rec.value = 0; \
SDP_CONN_STATE_MAX > (conn)->state_rec.value; \
@@ -174,10 +174,10 @@
(conn)->state_rec.line[(conn)->state_rec.value] = 0; \
} \
(conn)->state_rec.value = 0; \
-}
+} while(0)
#else
-#define SDP_CONN_ST_SET(conn, val) (conn)->state = (val)
-#define SDP_CONN_ST_INIT(conn) (conn)->state = SDP_CONN_ST_INVALID
+#define SDP_CONN_ST_SET(conn, val) ((conn)->state = (val))
+#define SDP_CONN_ST_INIT(conn) ((conn)->state = SDP_CONN_ST_INVALID)
#endif
/*
* connection lock
--
MST - Michael S. Tsirkin
More information about the general
mailing list