Skip to content

Commit e3cef0c

Browse files
felixendresFelix Endres
authored andcommitted
Update logging.h
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. Signed-off-by: Felix Endres <[email protected]>
1 parent a935f27 commit e3cef0c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

include/rcutils/logging.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,17 +516,18 @@ void rcutils_logging_console_output_handler(
516516
* All logging macros ensure that this has been called once.
517517
*/
518518
#define RCUTILS_LOGGING_AUTOINIT \
519-
if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
520-
rcutils_ret_t ret = rcutils_logging_initialize(); \
521-
if (ret != RCUTILS_RET_OK) { \
522-
RCUTILS_SAFE_FWRITE_TO_STDERR( \
523-
"[rcutils|" __FILE__ ":" RCUTILS_STRINGIFY(__LINE__) \
524-
"] error initializing logging: "); \
525-
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
526-
RCUTILS_SAFE_FWRITE_TO_STDERR("\n"); \
527-
rcutils_reset_error(); \
519+
do { \
520+
if (RCUTILS_UNLIKELY(!g_rcutils_logging_initialized)) { \
521+
if (rcutils_logging_initialize() != RCUTILS_RET_OK) { \
522+
RCUTILS_SAFE_FWRITE_TO_STDERR( \
523+
"[rcutils|" __FILE__ ":" RCUTILS_STRINGIFY(__LINE__) \
524+
"] error initializing logging: "); \
525+
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
526+
RCUTILS_SAFE_FWRITE_TO_STDERR("\n"); \
527+
rcutils_reset_error(); \
528+
} \
528529
} \
529-
}
530+
} while (0);
530531

531532
#ifdef __cplusplus
532533
}

0 commit comments

Comments
 (0)