From: Simon Marchi Date: Wed, 31 Mar 2021 14:46:20 +0000 (-0400) Subject: Clean-up: common: rename local variables in PERROR X-Git-Tag: v2.13.0-rc1~142 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=0c818c97b35a36971c326171d9aea5b0a432ced9 Clean-up: common: rename local variables in PERROR If PERROR is used in a function where a `buf` or `tmp` variable already exists, we get this when enabling -Wshadow: CC poll.lo In file included from /home/simark/src/lttng-tools/src/common/compat/poll.c:15: /home/simark/src/lttng-tools/src/common/compat/poll.c: In function ‘compat_epoll_set_max_size’: /home/simark/src/lttng-tools/src/common/error.h:247:9: error: declaration of ‘buf’ shadows a previous local [-Werror=shadow] 247 | char *buf; \ | ^~~ /home/simark/src/lttng-tools/src/common/compat/poll.c:335:3: note: in expansion of macro ‘PERROR’ 335 | PERROR("read set max size"); | ^~~~~~ /home/simark/src/lttng-tools/src/common/compat/poll.c:313:7: note: shadowed declaration is here 313 | char buf[64]; | ^~~ Avoid that by giving PERROR's variables names that are unlikely to be used elsewhere. Change-Id: I167491fd3b232e6cfd86d13c0003ad4facb40c58 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/error.h b/src/common/error.h index c4aa4012a..8af989e04 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -232,23 +232,24 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) /* * Version using XSI strerror_r. */ -#define PERROR(call, args...) \ - do { \ - char buf[200]; \ - strerror_r(errno, buf, sizeof(buf)); \ - _PERROR(call ": %s", ## args, buf); \ - } while(0); +#define PERROR(call, args...) \ + do { \ + char _perror_buf[200]; \ + strerror_r(errno, _perror_buf, sizeof(_perror_buf)); \ + _PERROR(call ": %s", ##args, _perror_buf); \ + } while (0); #else /* * Version using GNU strerror_r, for linux with appropriate defines. */ -#define PERROR(call, args...) \ - do { \ - char *buf; \ - char tmp[200]; \ - buf = strerror_r(errno, tmp, sizeof(tmp)); \ - _PERROR(call ": %s", ## args, buf); \ - } while(0); +#define PERROR(call, args...) \ + do { \ + char *_perror_buf; \ + char _perror_tmp[200]; \ + _perror_buf = strerror_r( \ + errno, _perror_tmp, sizeof(_perror_tmp)); \ + _PERROR(call ": %s", ##args, _perror_buf); \ + } while (0); #endif const char *error_get_str(int32_t code); diff --git a/tests/utils/utils.h b/tests/utils/utils.h index 48f937b1b..afacf8d2f 100644 --- a/tests/utils/utils.h +++ b/tests/utils/utils.h @@ -13,22 +13,23 @@ /* * Version using XSI strerror_r. */ -#define PERROR_NO_LOGGER(msg, args...) \ - do { \ - char buf[200]; \ - strerror_r(errno, buf, sizeof(buf)); \ - fprintf(stderr, msg ": %s\n", ##args, buf); \ +#define PERROR_NO_LOGGER(msg, args...) \ + do { \ + char _perror_buf[200]; \ + strerror_r(errno, _perror_buf, sizeof(_perror_buf)); \ + fprintf(stderr, msg ": %s\n", ##args, _perror_buf); \ } while (0); #else /* * Version using GNU strerror_r, for linux with appropriate defines. */ -#define PERROR_NO_LOGGER(msg, args...) \ - do { \ - char *buf; \ - char tmp[200]; \ - buf = strerror_r(errno, tmp, sizeof(tmp)); \ - fprintf(stderr, msg ": %s\n", ##args, buf); \ +#define PERROR_NO_LOGGER(msg, args...) \ + do { \ + char *_perror_buf; \ + char _perror_tmp[200]; \ + _perror_buf = strerror_r( \ + errno, _perror_tmp, sizeof(_perror_tmp)); \ + fprintf(stderr, msg ": %s\n", ##args, _perror_buf); \ } while (0); #endif