From: Dmitry V. Levin Date: Sat, 17 Jun 2017 21:47:57 +0000 (+0000) Subject: Fix macros encosure in a do/while loop X-Git-Tag: v4.18~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c08f7d65ca98c7ff031c7f6402ffcb051d39cc8;p=strace Fix macros encosure in a do/while loop 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. --- diff --git a/ipc_defs.h b/ipc_defs.h index fc5d88fe..740fd9de 100644 --- a/ipc_defs.h +++ b/ipc_defs.h @@ -41,8 +41,11 @@ # 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 */ diff --git a/test/seccomp.c b/test/seccomp.c index 00e6cca5..fac43b15 100644 --- a/test/seccomp.c +++ b/test/seccomp.c @@ -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); diff --git a/tests/ioctl_block.c b/tests/ioctl_block.c index 8e883d4b..e44c4c41 100644 --- a/tests/ioctl_block.c +++ b/tests/ioctl_block.c @@ -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) diff --git a/tests/ioctl_evdev.c b/tests/ioctl_evdev.c index 6cbc09fe..9d16cecf 100644 --- a/tests/ioctl_evdev.c +++ b/tests/ioctl_evdev.c @@ -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) diff --git a/tests/ioctl_mtd.c b/tests/ioctl_mtd.c index 71d0c0d1..6a7d94a7 100644 --- a/tests/ioctl_mtd.c +++ b/tests/ioctl_mtd.c @@ -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) diff --git a/tests/ioctl_v4l2.c b/tests/ioctl_v4l2.c index 9aac0172..f4ab6509 100644 --- a/tests/ioctl_v4l2.c +++ b/tests/ioctl_v4l2.c @@ -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 ) diff --git a/tests/poll.c b/tests/poll.c index c47c97e5..5c07297f 100644 --- a/tests/poll.c +++ b/tests/poll.c @@ -39,13 +39,15 @@ # include # include -#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("}"); } diff --git a/tests/xchownx.c b/tests/xchownx.c index fe582835..e415feff 100644 --- a/tests/xchownx.c +++ b/tests/xchownx.c @@ -45,10 +45,17 @@ # 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 diff --git a/tests/xstatfsx.c b/tests/xstatfsx.c index cb524ff3..33254dd9 100644 --- a/tests/xstatfsx.c +++ b/tests/xstatfsx.c @@ -38,12 +38,17 @@ #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) diff --git a/tests/xstatx.c b/tests/xstatx.c index 8758ef81..305a7262 100644 --- a/tests/xstatx.c +++ b/tests/xstatx.c @@ -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 3df11e8e..a63295e1 100644 --- 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); diff --git a/unwind.c b/unwind.c index 514246c7..5b51930c 100644 --- a/unwind.c +++ b/unwind.c @@ -39,7 +39,11 @@ # 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,