From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Benjamin Marzinski" Subject: [PATCH 06/17] libmultipath: fix PAD and PRINT macros Date: Mon, 28 Mar 2016 22:13:03 -0500 Message-ID: <1459221194-23222-7-git-send-email-bmarzins@redhat.com> References: <1459221194-23222-1-git-send-email-bmarzins@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1459221194-23222-1-git-send-email-bmarzins@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: device-mapper development Cc: Christophe Varoqui List-Id: dm-devel.ids 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 --- 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