Skip to content

Comments

motion-logger: Do not use value passed unchecked to access array#3829

Open
smoe wants to merge 1 commit intoLinuxCNC:2.9from
smoe:motion_check_joints
Open

motion-logger: Do not use value passed unchecked to access array#3829
smoe wants to merge 1 commit intoLinuxCNC:2.9from
smoe:motion_check_joints

Conversation

@smoe
Copy link
Collaborator

@smoe smoe commented Feb 24, 2026

Please kindly have an extra eye on me setting <,<=,> correctly. Maybe these checks are not required because those checks are already performed elsewhere. Still, it feels weird to not perform such checks. The major question though is if enough is done if any such invalid number is observed.

@smoe smoe added the for-discussion-only This pull request is intended as a basis for discussion, not to be merged as-is label Feb 24, 2026
@BsAtHome
Copy link
Contributor

IIRC, axis checks should also check the mask because you have, for example, XZA configs where Y-axis is effectively invalid. But you need to have access to the axis_mask in trajectory stat, emcStatus->motion.traj.axis_mask, which holds the valid axis as a bit mask. Don't know if that is exposed somehow, somewhere. If not, then the index check should suffice. Writing to unused axes should have no effect if the kinematics play nice.

The checks could also be slightly simplified as:

// valid: zero inclusive, max exclusive
if (joint >= 0 && joint < EMCMOT_MAX_JOINTS) {
  // valid, use joint as index
} else {
  log_print("...invalid joint index %d. Valid range [0,%d]\n", joint, EMCMOT_MAX_JOINTS-1);
}

And, why do you split lines on closing curly brace and an else clause? You'd normally write that as:

if (bla) {
  something();
} else {  // <-- this line
  something_else();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for-discussion-only This pull request is intended as a basis for discussion, not to be merged as-is

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants