]> granicus.if.org Git - strace/commitdiff
Fix macros encosure in a do/while loop
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 17 Jun 2017 21:47:57 +0000 (21:47 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 17 Jun 2017 21:51:48 +0000 (21:51 +0000)
Enclose macros with multiple statements and macros starting
with "if" statement in a do/while loop.
Do not enclose single statement macros in a do/while loop.

Reported by kernel's checkpatch.pl script.

12 files changed:
ipc_defs.h
test/seccomp.c
tests/ioctl_block.c
tests/ioctl_evdev.c
tests/ioctl_mtd.c
tests/ioctl_v4l2.c
tests/poll.c
tests/xchownx.c
tests/xstatfsx.c
tests/xstatx.c
uname.c
unwind.c

index fc5d88fe27ad27c59548797471547b4945bbc34b..740fd9de01a7ca41c80bcf8c36864771d457a263 100644 (file)
 # define IPC_64 0x100
 #endif
 
-#define PRINTCTL(flagset, arg, dflt) \
-       if ((arg) & IPC_64) tprints("IPC_64|"); \
-       printxval((flagset), (arg) &~ IPC_64, dflt)
+#define PRINTCTL(flagset, arg, dflt)                           \
+       do {                                                    \
+               if ((arg) & IPC_64)                             \
+                       tprints("IPC_64|");                     \
+               printxval((flagset), (arg) & ~IPC_64, dflt);    \
+       } while (0)
 
 #endif /* !STRACE_IPC_DEFS_H */
index 00e6cca5cb1998015ae7b919145a77f4be59ca71..fac43b15fea5795aba373ed348db642eec764a1b 100644 (file)
@@ -80,9 +80,13 @@ main(void)
        if (close(0) || close(1))
                _exit(1);
 
-#define TEST_DENIED_SYSCALL(nr, err, fail) \
-       if (errno = 0, syscall(__NR_ ## nr, 0xbad, 0xf00d, 0xdead, 0xbeef, err, fail) != -1 || err != errno) \
-               close(-fail)
+#define TEST_DENIED_SYSCALL(nr, err, fail)                                                     \
+       do {                                                                                    \
+               errno = 0;                                                                      \
+               if (syscall(__NR_ ## nr, 0xbad, 0xf00d, 0xdead, 0xbeef, err, fail) != -1        \
+                   || err != errno)                                                            \
+                       close(-fail);                                                           \
+       } while (0)
 
        TEST_DENIED_SYSCALL(sync, EBUSY, 2);
        TEST_DENIED_SYSCALL(setsid, EACCES, 3);
index 8e883d4b2440c364ca0240b12431e87817f601ab..e44c4c41ed2f7365b9852a83cd766cb0b33e4ded 100644 (file)
@@ -58,9 +58,11 @@ static struct xlat block_argless[] = {
 #endif
 };
 
-#define TEST_NULL_ARG(cmd) \
-       ioctl(-1, cmd, 0); \
-       printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd)
+#define TEST_NULL_ARG(cmd)                                             \
+       do {                                                            \
+               ioctl(-1, cmd, 0);                                      \
+               printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd);  \
+       } while (0)
 
 int
 main(void)
index 6cbc09feb77b159d2b51cae8d10104d2d4d60706..9d16cecf0877febd26f437572e3b2b738de13dfc 100644 (file)
@@ -67,9 +67,11 @@ print_ffe_common(const struct ff_effect *const ffe, const char *const type_str)
 # endif /* VERBOSE */
 }
 
-# define TEST_NULL_ARG(cmd) \
-       ioctl(-1, cmd, 0); \
-       printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd)
+# define TEST_NULL_ARG(cmd)                                            \
+       do {                                                            \
+               ioctl(-1, cmd, 0);                                      \
+               printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd);  \
+       } while (0)
 
 int
 main(void)
index 71d0c0d1e5c40c2c9e95951803e55ec35ed97651..6a7d94a7c9d5f085e7283b0b33bf1b61fc267aed 100644 (file)
@@ -58,15 +58,17 @@ static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
                               (unsigned int) _IOC_NR(cmd), #cmd); \
                else \
                        printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd); \
-               } while (0)
-
-#define TEST_erase_info_user(cmd, eiu) \
-       ioctl(-1, cmd, eiu); \
-       printf("ioctl(-1, MIXER_%s(%u) or %s, {start=%#x, length=%#x})" \
-              " = -1 EBADF (%m)\n", \
-              (_IOC_DIR(cmd) == _IOC_READ) ? "READ" : "WRITE", \
-              (unsigned int) _IOC_NR(cmd), #cmd, \
-              eiu->start, eiu->length)
+       } while (0)
+
+#define TEST_erase_info_user(cmd, eiu)                                         \
+       do {                                                                    \
+               ioctl(-1, cmd, eiu);                                            \
+               printf("ioctl(-1, MIXER_%s(%u) or %s, {start=%#x, length=%#x})" \
+                      " = -1 EBADF (%m)\n",                                    \
+                      (_IOC_DIR(cmd) == _IOC_READ) ? "READ" : "WRITE",         \
+                      (unsigned int) _IOC_NR(cmd), #cmd,                       \
+                      eiu->start, eiu->length);                                \
+       } while (0)
 
 int
 main(void)
index 9aac01727fede0fb4b0c36c8ced0052053bf1aaa..f4ab65090ec8b7ab5afd3e004bf093736d8e4184 100644 (file)
@@ -319,9 +319,8 @@ dprint_ioctl_v4l2(struct v4l2_format *const f,
 #endif
        }
 }
-#define print_ioctl_v4l2(v4l2_format, request, buf_type) do { \
-       dprint_ioctl_v4l2((v4l2_format), (request), (buf_type), #buf_type); \
-} while (0)
+#define print_ioctl_v4l2(v4l2_format, request, buf_type)       \
+       dprint_ioctl_v4l2((v4l2_format), (request), (buf_type), #buf_type)
 
 int
 main(void )
index c47c97e51ea619978643bacb677884fc537e6abe..5c07297fc562b6fa673d3d4b3fe43aa4749d7359 100644 (file)
 # include <stdlib.h>
 # include <unistd.h>
 
-#define PRINT_EVENT(flag, member) \
-       if (member & flag) { \
-               if (member != pfd->member) \
-                       tprintf("|"); \
-               tprintf(#flag); \
-               member &= ~flag; \
-       }
+#define PRINT_EVENT(flag, member)                      \
+       do {                                            \
+               if (member & flag) {                    \
+                       if (member != pfd->member)      \
+                               tprintf("|");           \
+                       tprintf(#flag);                 \
+                       member &= ~flag;                \
+               }                                       \
+       } while (0)
 
 static void
 print_pollfd_entering(const struct pollfd *const pfd)
@@ -56,24 +58,24 @@ print_pollfd_entering(const struct pollfd *const pfd)
                short events = pfd->events;
 
                if (pfd->events) {
-                       PRINT_EVENT(POLLIN, events)
-                       PRINT_EVENT(POLLPRI, events)
-                       PRINT_EVENT(POLLOUT, events)
+                       PRINT_EVENT(POLLIN, events);
+                       PRINT_EVENT(POLLPRI, events);
+                       PRINT_EVENT(POLLOUT, events);
 #ifdef POLLRDNORM
-                       PRINT_EVENT(POLLRDNORM, events)
+                       PRINT_EVENT(POLLRDNORM, events);
 #endif
 #ifdef POLLWRNORM
-                       PRINT_EVENT(POLLWRNORM, events)
+                       PRINT_EVENT(POLLWRNORM, events);
 #endif
 #ifdef POLLRDBAND
-                       PRINT_EVENT(POLLRDBAND, events)
+                       PRINT_EVENT(POLLRDBAND, events);
 #endif
 #ifdef POLLWRBAND
-                       PRINT_EVENT(POLLWRBAND, events)
+                       PRINT_EVENT(POLLWRBAND, events);
 #endif
-                       PRINT_EVENT(POLLERR, events)
-                       PRINT_EVENT(POLLHUP, events)
-                       PRINT_EVENT(POLLNVAL, events)
+                       PRINT_EVENT(POLLERR, events);
+                       PRINT_EVENT(POLLHUP, events);
+                       PRINT_EVENT(POLLNVAL, events);
                } else
                        tprintf("0");
        }
@@ -123,24 +125,24 @@ print_pollfd_exiting(const struct pollfd *const pfd,
        tprintf("{fd=%d, revents=", pfd->fd);
        short revents = pfd->revents;
 
-       PRINT_EVENT(POLLIN, revents)
-       PRINT_EVENT(POLLPRI, revents)
-       PRINT_EVENT(POLLOUT, revents)
+       PRINT_EVENT(POLLIN, revents);
+       PRINT_EVENT(POLLPRI, revents);
+       PRINT_EVENT(POLLOUT, revents);
 #ifdef POLLRDNORM
-       PRINT_EVENT(POLLRDNORM, revents)
+       PRINT_EVENT(POLLRDNORM, revents);
 #endif
 #ifdef POLLWRNORM
-       PRINT_EVENT(POLLWRNORM, revents)
+       PRINT_EVENT(POLLWRNORM, revents);
 #endif
 #ifdef POLLRDBAND
-       PRINT_EVENT(POLLRDBAND, revents)
+       PRINT_EVENT(POLLRDBAND, revents);
 #endif
 #ifdef POLLWRBAND
-       PRINT_EVENT(POLLWRBAND, revents)
+       PRINT_EVENT(POLLWRBAND, revents);
 #endif
-       PRINT_EVENT(POLLERR, revents)
-       PRINT_EVENT(POLLHUP, revents)
-       PRINT_EVENT(POLLNVAL, revents)
+       PRINT_EVENT(POLLERR, revents);
+       PRINT_EVENT(POLLHUP, revents);
+       PRINT_EVENT(POLLNVAL, revents);
        tprintf("}");
 }
 
index fe5828351d5b65e2a856a2b9ede123c724afa597..e415feff6300c988a99ffffca71ec1c764665d49 100644 (file)
 # define CHECK_OVERFLOWGID(arg)
 #endif
 
-#define UNLINK_SAMPLE \
-       if (unlink(sample)) perror_msg_and_fail("unlink")
-#define CLOSE_SAMPLE \
-       if (close(fd)) perror_msg_and_fail("close")
+#define UNLINK_SAMPLE                                  \
+       do {                                            \
+               if (unlink(sample))                     \
+                       perror_msg_and_fail("unlink");  \
+       } while (0)
+
+#define CLOSE_SAMPLE                                   \
+       do {                                            \
+               if (close(fd))                          \
+                       perror_msg_and_fail("close");   \
+       } while (0)
 
 #ifdef ACCESS_BY_DESCRIPTOR
 # define SYSCALL_ARG1 fd
index cb524ff3eddaee52b03c787887388f52a2f8219f..33254dd9078e9af18d079763c217db6123b1d4d4 100644 (file)
 #include "xlat/statfs_flags.h"
 
 #define PRINT_NUM(arg)                                                 \
-       if (sizeof(b->arg) == sizeof(int))                              \
-               printf(", %s=%u", #arg, (unsigned int) b->arg);         \
-       else if (sizeof(b->arg) == sizeof(long))                                \
-               printf(", %s=%lu", #arg, (unsigned long) b->arg);       \
-       else                                                            \
-               printf(", %s=%llu", #arg, (unsigned long long) b->arg)
+       do {                                                            \
+               if (sizeof(b->arg) == sizeof(int))                      \
+                       printf(", %s=%u", #arg,                         \
+                              (unsigned int) b->arg);                  \
+               else if (sizeof(b->arg) == sizeof(long))                \
+                       printf(", %s=%lu", #arg,                        \
+                              (unsigned long) b->arg);                 \
+               else                                                    \
+                       printf(", %s=%llu", #arg,                       \
+                              (unsigned long long) b->arg);            \
+       } while (0)
 
 static void
 print_statfs_type(const char *const prefix, const unsigned int magic)
index 8758ef817ce87be895f6541a7627734eeb116253..305a7262390af4238bae84fe2f45c9545afe822d 100644 (file)
@@ -178,14 +178,16 @@ print_stat(const STRUCT_STAT *st)
 #   define HAVE_NSEC           0
 #  endif
 
-#define PRINT_ST_TIME(field)                                           \
-       printf(", st_" #field "=%lld",                                  \
-              sign_extend_unsigned_to_ll(st->st_ ## field));           \
-       print_time_t_nsec(sign_extend_unsigned_to_ll(st->st_ ## field), \
-                         TIME_NSEC(st->st_ ## field ## _nsec), 1);     \
-       if (HAVE_NSEC)                                                  \
-               printf(", st_" #field "_nsec=%llu",                     \
-                      TIME_NSEC(st->st_ ## field ## _nsec))
+#define PRINT_ST_TIME(field)                                                   \
+       do {                                                                    \
+               printf(", st_" #field "=%lld",                                  \
+                      sign_extend_unsigned_to_ll(st->st_ ## field));           \
+               print_time_t_nsec(sign_extend_unsigned_to_ll(st->st_ ## field), \
+                                 TIME_NSEC(st->st_ ## field ## _nsec), 1);     \
+               if (HAVE_NSEC)                                                  \
+                       printf(", st_" #field "_nsec=%llu",                     \
+                              TIME_NSEC(st->st_ ## field ## _nsec));           \
+       } while (0)
 
        PRINT_ST_TIME(atime);
        PRINT_ST_TIME(mtime);
@@ -201,18 +203,24 @@ print_stat(const STRUCT_STAT *st)
 #  define PRINT_FIELD_U(field) \
        printf(", %s=%llu", #field, (unsigned long long) st->field)
 
-#  define PRINT_FIELD_U32_UID(field) \
-       if (st->field == (uint32_t) -1) \
-               printf(", %s=-1", #field); \
-       else \
-               printf(", %s=%llu", #field, (unsigned long long) st->field)
-
-#  define PRINT_FIELD_TIME(field)                                      \
-       printf(", %s={tv_sec=%lld, tv_nsec=%u}",                        \
-              #field, (long long) st->field.tv_sec,                    \
-              (unsigned) st->field.tv_nsec);                           \
-       print_time_t_nsec(st->field.tv_sec,                             \
-                         zero_extend_signed_to_ull(st->field.tv_nsec), 1);
+#  define PRINT_FIELD_U32_UID(field)                                   \
+       do {                                                            \
+               if (st->field == (uint32_t) -1)                         \
+                       printf(", %s=-1", #field);                      \
+               else                                                    \
+                       printf(", %s=%llu", #field,                     \
+                              (unsigned long long) st->field);         \
+       } while (0)
+
+#  define PRINT_FIELD_TIME(field)                                              \
+       do {                                                                    \
+               printf(", %s={tv_sec=%lld, tv_nsec=%u}",                        \
+                      #field, (long long) st->field.tv_sec,                    \
+                      (unsigned) st->field.tv_nsec);                           \
+               print_time_t_nsec(st->field.tv_sec,                             \
+                                 zero_extend_signed_to_ull(st->field.tv_nsec), \
+                                 1);                                           \
+       } while (0)
 
        printf("{stx_mask=");
        printflags(statx_masks, st->stx_mask, "STATX_???");
@@ -388,24 +396,30 @@ main(void)
 
 # if IS_STATX
 
-#  define INVOKE() \
-       rc = TEST_SYSCALL_INVOKE(sample, st); \
-       PRINT_SYSCALL_HEADER(sample); \
-       if (rc) \
-               printf("%p", st); \
-       else \
-               print_stat(st); \
-       PRINT_SYSCALL_FOOTER(rc)
-
-#  define SET_FLAGS_INVOKE(flags, flags_str) \
-       TEST_SYSCALL_STATX_FLAGS = flags; \
-       TEST_SYSCALL_STATX_FLAGS_STR = flags_str; \
-       INVOKE()
-
-#  define SET_MASK_INVOKE(mask, mask_str) \
-       TEST_SYSCALL_STATX_MASK = mask; \
-       TEST_SYSCALL_STATX_MASK_STR = mask_str; \
-       INVOKE()
+#  define INVOKE()                                     \
+       do {                                            \
+               rc = TEST_SYSCALL_INVOKE(sample, st);   \
+               PRINT_SYSCALL_HEADER(sample);           \
+               if (rc)                                 \
+                       printf("%p", st);               \
+               else                                    \
+                       print_stat(st);                 \
+               PRINT_SYSCALL_FOOTER(rc);               \
+       } while (0)
+
+#  define SET_FLAGS_INVOKE(flags, flags_str)                   \
+       do {                                                    \
+               TEST_SYSCALL_STATX_FLAGS = flags;               \
+               TEST_SYSCALL_STATX_FLAGS_STR = flags_str;       \
+               INVOKE();                                       \
+       } while (0)
+
+#  define SET_MASK_INVOKE(mask, mask_str)                      \
+       do {                                                    \
+               TEST_SYSCALL_STATX_MASK = mask;                 \
+               TEST_SYSCALL_STATX_MASK_STR = mask_str;         \
+               INVOKE();                                       \
+       } while (0)
 
        unsigned old_flags = TEST_SYSCALL_STATX_FLAGS;
        const char *old_flags_str = TEST_SYSCALL_STATX_FLAGS_STR;
diff --git a/uname.c b/uname.c
index 3df11e8ee470fe1e1438c4b9f2a6c5fce7a348c0..a63295e1231c561c0ef5cba0eb15a8ee265a4093 100644 (file)
--- a/uname.c
+++ b/uname.c
@@ -41,10 +41,12 @@ SYS_FUNC(uname)
                return 0;
 
        if (!umove_or_printaddr(tcp, tcp->u_arg[0], &uname)) {
-#define PRINT_UTS_MEMBER(prefix, member) \
-               tprints(prefix #member "="); \
-               print_quoted_string(uname.member, sizeof(uname.member), \
-                                   QUOTE_0_TERMINATED)
+#define PRINT_UTS_MEMBER(prefix, member)                               \
+       do {                                                            \
+               tprints(prefix #member "=");                            \
+               print_quoted_string(uname.member, sizeof(uname.member), \
+                                   QUOTE_0_TERMINATED);                \
+       } while (0)
 
                PRINT_UTS_MEMBER("{", sysname);
                PRINT_UTS_MEMBER(", ", nodename);
index 514246c74a0760234036ef7d12b379ed4c07cf13..5b51930c6906a3246c60dec4781ed18a757bc09d 100644 (file)
--- a/unwind.c
+++ b/unwind.c
 # define fopen_for_input fopen
 #endif
 
-#define DPRINTF(F, A, ...) if (debug_flag) error_msg("[unwind(" A ")] " F, __VA_ARGS__)
+#define DPRINTF(F, A, ...)                                             \
+       do {                                                            \
+               if (debug_flag)                                         \
+                       error_msg("[unwind(" A ")] " F, __VA_ARGS__);   \
+       } while (0)
 
 /*
  * Keep a sorted array of cache entries,