Skip to content

Commit d5baf85

Browse files
authored
suppress false positive from clang-tidy (#951)
* suppress false positive from clang-tidy Signed-off-by: William Woodall <[email protected]> * document undefined behavior in logging functions Signed-off-by: William Woodall <[email protected]>
1 parent cae279a commit d5baf85

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

rcl/include/rcl/logging_rosout.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ rcl_logging_rosout_fini_publisher_for_node(
158158
* message out via that publisher. If there is no publisher directly correlated
159159
* with the logger then nothing will be done.
160160
*
161-
* This function is meant to be registered with the logging functions for rcutils
161+
* This function is meant to be registered with the logging functions for
162+
* rcutils, and shouldn't be used outside of that context.
163+
* Additionally, arguments like args should be non-null and properly initialized
164+
* otherwise it is undefined behavior.
162165
*
163166
* <hr>
164167
* Attribute | Adherence
@@ -176,7 +179,8 @@ rcl_logging_rosout_fini_publisher_for_node(
176179
* \param[in] args argument for the string format
177180
*/
178181
RCL_PUBLIC
179-
void rcl_logging_rosout_output_handler(
182+
void
183+
rcl_logging_rosout_output_handler(
180184
const rcutils_log_location_t * location,
181185
int severity,
182186
const char * name,

rcl/src/rcl/logging.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ static
165165
void
166166
rcl_logging_ext_lib_output_handler(
167167
const rcutils_log_location_t * location,
168-
int severity, const char * name, rcutils_time_point_value_t timestamp,
169-
const char * format, va_list * args)
168+
int severity,
169+
const char * name,
170+
rcutils_time_point_value_t timestamp,
171+
const char * format,
172+
va_list * args)
170173
{
171174
rcl_ret_t status;
172175
char msg_buf[1024] = "";
@@ -188,7 +191,9 @@ rcl_logging_ext_lib_output_handler(
188191
};
189192

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

rcl/src/rcl/logging_rosout.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,11 @@ rcl_ret_t rcl_logging_rosout_fini_publisher_for_node(
231231

232232
void rcl_logging_rosout_output_handler(
233233
const rcutils_log_location_t * location,
234-
int severity, const char * name, rcutils_time_point_value_t timestamp,
235-
const char * format, va_list * args)
234+
int severity,
235+
const char * name,
236+
rcutils_time_point_value_t timestamp,
237+
const char * format,
238+
va_list * args)
236239
{
237240
rosout_map_entry_t entry;
238241
rcl_ret_t status = RCL_RET_OK;
@@ -251,7 +254,9 @@ void rcl_logging_rosout_output_handler(
251254
};
252255

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

0 commit comments

Comments
 (0)