Document changes to rclcpp's logging macros#949
Conversation
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
clalancette
left a comment
There was a problem hiding this comment.
I added some suggestions to give users more context on what they may need to change.
|
(also, this PR should not be merged until we land ros2/rclcpp#1442) |
Signed-off-by: Audrow Nash <audrow.nash@gmail.com> Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
|
I've updated the |
| If you are using a ``std::string`` as a format string with format arguments, converting that string to a ``char *`` and using it as the format string will yield a format security warning. To avoid the security warning, we recommend you build the string manually and pass it as in with no format arguments like the previous example. | ||
|
|
||
| If you don't care about the ``-Wformat-security`` warning and you previously had code like: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| std::string my_std_string = "Foo %d"; | ||
| RCLCPP_DEBUG(get_logger(), my_std_string, 5); | ||
|
|
||
| you could replace it with: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| std::string my_std_string = "Foo %d"; | ||
| RCLCPP_DEBUG(get_logger(), my_std_string.c_str(), 5); // raises -Wformat-security warning |
There was a problem hiding this comment.
Honestly, I think this is somewhat redundant with the previous example. Also, I think we should explain why it ends up with the -Wformat-security warning. So I'd think about replacing this entire block with:
Note: if you are using a ``std::string`` as a format string with format arguments, converting that string to a ``char *`` and using it as the format string will yield a format security warning. That's because the compiler has no way at compile to introspect into the ``std::string`` to verify the arguments. To avoid the security warning, we recommend you build the string manually and pass it in with no format arguments like the previous example.
There was a problem hiding this comment.
Good call, I think this makes it much clearer.
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
* Add changes to rclcpp's logging macros Signed-off-by: Audrow Nash <audrow.nash@gmail.com> Co-authored-by: Chris Lalancette <clalancette@openrobotics.org> (cherry picked from commit 15eb141) Co-authored-by: Audrow Nash <audrow.nash@gmail.com>
* Add changes to rclcpp's logging macros Signed-off-by: Audrow Nash <audrow.nash@gmail.com> Co-authored-by: Chris Lalancette <clalancette@openrobotics.org> (cherry picked from commit 15eb141) Co-authored-by: Audrow Nash <audrow.nash@gmail.com>
This PR documents the changes from ros2/rclcpp#1442.