Skip to content

Commit

Permalink
suppress false positive from clang-tidy (#951)
Browse files Browse the repository at this point in the history
* suppress false positive from clang-tidy

Signed-off-by: William Woodall <william@osrfoundation.org>

* document undefined behavior in logging functions

Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood authored Mar 22, 2022
1 parent cae279a commit d5baf85
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 6 additions & 2 deletions rcl/include/rcl/logging_rosout.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ rcl_logging_rosout_fini_publisher_for_node(
* message out via that publisher. If there is no publisher directly correlated
* with the logger then nothing will be done.
*
* This function is meant to be registered with the logging functions for rcutils
* This function is meant to be registered with the logging functions for
* rcutils, and shouldn't be used outside of that context.
* Additionally, arguments like args should be non-null and properly initialized
* otherwise it is undefined behavior.
*
* <hr>
* Attribute | Adherence
Expand All @@ -176,7 +179,8 @@ rcl_logging_rosout_fini_publisher_for_node(
* \param[in] args argument for the string format
*/
RCL_PUBLIC
void rcl_logging_rosout_output_handler(
void
rcl_logging_rosout_output_handler(
const rcutils_log_location_t * location,
int severity,
const char * name,
Expand Down
11 changes: 8 additions & 3 deletions rcl/src/rcl/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ static
void
rcl_logging_ext_lib_output_handler(
const rcutils_log_location_t * location,
int severity, const char * name, rcutils_time_point_value_t timestamp,
const char * format, va_list * args)
int severity,
const char * name,
rcutils_time_point_value_t timestamp,
const char * format,
va_list * args)
{
rcl_ret_t status;
char msg_buf[1024] = "";
Expand All @@ -188,7 +191,9 @@ rcl_logging_ext_lib_output_handler(
};

va_list args_clone;
va_copy(args_clone, *args);
// The args are initialized, but clang-tidy cannot tell.
// It may be related to this bug: https://bugs.llvm.org/show_bug.cgi?id=41311
va_copy(args_clone, *args); // NOLINT(clang-analyzer-valist.Uninitialized)
status = rcutils_char_array_vsprintf(&msg_array, format, args_clone);
va_end(args_clone);

Expand Down
11 changes: 8 additions & 3 deletions rcl/src/rcl/logging_rosout.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ rcl_ret_t rcl_logging_rosout_fini_publisher_for_node(

void rcl_logging_rosout_output_handler(
const rcutils_log_location_t * location,
int severity, const char * name, rcutils_time_point_value_t timestamp,
const char * format, va_list * args)
int severity,
const char * name,
rcutils_time_point_value_t timestamp,
const char * format,
va_list * args)
{
rosout_map_entry_t entry;
rcl_ret_t status = RCL_RET_OK;
Expand All @@ -251,7 +254,9 @@ void rcl_logging_rosout_output_handler(
};

va_list args_clone;
va_copy(args_clone, *args);
// The args are initialized, but clang-tidy cannot tell.
// It may be related to this bug: https://bugs.llvm.org/show_bug.cgi?id=41311
va_copy(args_clone, *args); // NOLINT(clang-analyzer-valist.Uninitialized)
RCL_RET_FROM_RCUTIL_RET(status, rcutils_char_array_vsprintf(&msg_array, format, args_clone));
va_end(args_clone);
if (RCL_RET_OK != status) {
Expand Down

0 comments on commit d5baf85

Please sign in to comment.