[dm-devel] [PATCH 06/17] libmultipath: fix PAD and PRINT macros

Benjamin Marzinski bmarzins at redhat.com
Tue Mar 29 03:13:03 UTC 2016


The PAD and PRINT macros are multi-line macros that aren't enclosed in
braces. This means that if they are used as single line code blocks
with no braces, they won't work correctly. This is currently happening
with the PAD macro, but should be fixed in both.

Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>
---
 libmultipath/print.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 6215d0b..13d076a 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -32,14 +32,21 @@
 #define MAX(x,y) (x > y) ? x : y
 #define TAIL     (line + len - 1 - c)
 #define NOPAD    s = c
-#define PAD(x)   while ((int)(c - s) < (x) && (c < (line + len - 1))) \
-			*c++ = ' '; s = c
+#define PAD(x) \
+do { \
+	while ((int)(c - s) < (x) && (c < (line + len - 1))) \
+		*c++ = ' '; \
+	s = c; \
+} while (0)
+
 #define ENDLINE \
 		if (c > line) \
 			line[c - line - 1] = '\n'
-#define PRINT(var, size, format, args...)      \
-		fwd = snprintf(var, size, format, ##args); \
-		 c += (fwd >= size) ? size : fwd;
+#define PRINT(var, size, format, args...) \
+do { \
+	fwd = snprintf(var, size, format, ##args); \
+	c += (fwd >= size) ? size : fwd; \
+} while (0)
 
 /*
  * information printing helpers
-- 
1.8.3.1




More information about the dm-devel mailing list