Skip to content

Commit

Permalink
Update logging.h
Browse files Browse the repository at this point in the history
Fix issue #285:
Remove the temporary variable in a macro, because the name of the variable may shadow a variable of the macro user.
As suggested by @clalancette, also wrapped it into a do-while wrapping.
  • Loading branch information
felixendres authored Sep 11, 2020
1 parent a935f27 commit 3bc0f2b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions include/rcutils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,18 @@ void rcutils_logging_console_output_handler(
* All logging macros ensure that this has been called once.
*/
#define RCUTILS_LOGGING_AUTOINIT \
if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
rcutils_ret_t ret = rcutils_logging_initialize(); \
if (ret != RCUTILS_RET_OK) { \
RCUTILS_SAFE_FWRITE_TO_STDERR( \
"[rcutils|" __FILE__ ":" RCUTILS_STRINGIFY(__LINE__) \
"] error initializing logging: "); \
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
RCUTILS_SAFE_FWRITE_TO_STDERR("\n"); \
rcutils_reset_error(); \
do { \
if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
if (rcutils_logging_initialize() != RCUTILS_RET_OK) { \
RCUTILS_SAFE_FWRITE_TO_STDERR( \
"[rcutils|" __FILE__ ":" RCUTILS_STRINGIFY(__LINE__) \
"] error initializing logging: "); \
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
RCUTILS_SAFE_FWRITE_TO_STDERR("\n"); \
rcutils_reset_error(); \
} \
} \
}
} while (0);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 3bc0f2b

Please sign in to comment.