fix(crane_msgs,crane_robot_receiver): kick_stateの×10スケールによるuint8オーバーフローを修正#1399
Open
HansRobo wants to merge 1 commit into
Open
fix(crane_msgs,crane_robot_receiver): kick_stateの×10スケールによるuint8オーバーフローを修正#1399HansRobo wants to merge 1 commit into
HansRobo wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
crane_robot_receiverのRobotFeedback.kick_stateは、生バイトをKICK_STATE_SCALE(=10)でスケールした値を保持する。しかし格納先がuint8(0〜255)であったため、スケール後の値が256以上になると剰余化(オーバーフロー)していた。本PRではkick_stateの型をuint8→uint16に変更し、スケール後の値域を正しく保持する。問題
crane_robot_receiver/src/robot_receiver_node.cpp:192-193で以下のように代入している。生バイトが26以上の場合、積が256を超え
uint8の範囲を超過して剰余化する。例: 生バイト 30 → 30 × 10 = 300 → uint8 へ縮小代入で 300 mod 256 = 44 となり、本来の 300 が 44 として観測される。
原因
スケール後の値域(最大 255 × 10 = 2550)を保持できる型ではなく、
RobotFeedback.msgの定義およびrobot_feedback_protocol.hppのstruct RobotFeedbackメンバがともにuint8のままだった。修正内容
crane_msgs/msg/RobotFeedback.msg:uint8 kick_state→uint16 kick_statecrane_robot_receiver/include/crane_robot_receiver/robot_feedback_protocol.hpp:struct RobotFeedbackのuint8_t kick_state→uint16_t kick_stateこれによりスケール後の値域(最大 2550)を欠損なく保持できる。代入式(line 192-193)は整数演算の結果を
uint16に格納するため、追加のキャストは不要。検証
cwm の独立オーバーレイ worktree 上で
colcon build(--no-rdeps、MAKEFLAGS=-j3/CMAKE_BUILD_PARALLEL_LEVEL=3)を実行し、crane_msgsおよびcrane_robot_receiverのコンパイルが成功(Build complete.)することを確認した。stderr には CMake のバージョン非推奨警告のみが含まれ、ビルド失敗はない。レビュー観点
crane_msgsのメッセージ定義(RobotFeedback.msg)変更を含む。下流(web debugger 等)の consumer はkick_stateを整数として表示するため、uint8→uint16への拡大は互換である。本PRはソースコード監査ワークフローで検出・敵対的検証されたバグに対する単一修正です。