Skip to content

Commit 9be1c8b

Browse files
bnmguybmourit
authored andcommitted
Prevent a possible nullptr dereference
1 parent e766292 commit 9be1c8b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Marlin/src/module/ft_motion.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ xyze_long_t FTMotion::steps = { 0 }; // Step count accumulator.
8989

9090
uint32_t FTMotion::interpIdx = 0; // Index of current data point being interpolated.
9191

92+
uint8_t FTMotion::current_extruder_idx = 0; // Cached extruder index.
93+
9294
// Shaping variables.
9395
#if HAS_FTM_SHAPING
9496
FTMotion::shaping_t FTMotion::shaping = {
@@ -391,6 +393,8 @@ void FTMotion::reset() {
391393
TERN_(HAS_EXTRUDERS, e_raw_z1 = e_advanced_z1 = 0.0f);
392394

393395
axis_move_end_ti.reset();
396+
397+
current_extruder_idx = 0;
394398
}
395399

396400
// Private functions.
@@ -454,6 +458,9 @@ void FTMotion::init() {
454458
// Load / convert block data from planner to fixed-time control variables.
455459
void FTMotion::loadBlockData(block_t * const current_block) {
456460

461+
// Cache the extruder index for this block
462+
current_extruder_idx = current_block->extruder;
463+
457464
const float totalLength = current_block->millimeters,
458465
oneOverLength = 1.0f / totalLength;
459466

@@ -721,7 +728,7 @@ void FTMotion::convertToSteps(const uint32_t idx) {
721728
#if ENABLED(STEPS_ROUNDING)
722729
#define TOSTEPS(A,B) int32_t(trajMod.A[idx] * planner.settings.axis_steps_per_mm[B] + (trajMod.A[idx] < 0.0f ? -0.5f : 0.5f))
723730
const xyze_long_t steps_tar = LOGICAL_AXIS_ARRAY(
724-
TOSTEPS(e, E_AXIS_N(stepper.current_block->extruder)), // May be eliminated if guaranteed positive.
731+
TOSTEPS(e, E_AXIS_N(current_extruder_idx)), // May be eliminated if guaranteed positive.
725732
TOSTEPS(x, X_AXIS), TOSTEPS(y, Y_AXIS), TOSTEPS(z, Z_AXIS),
726733
TOSTEPS(i, I_AXIS), TOSTEPS(j, J_AXIS), TOSTEPS(k, K_AXIS),
727734
TOSTEPS(u, U_AXIS), TOSTEPS(v, V_AXIS), TOSTEPS(w, W_AXIS)
@@ -730,7 +737,7 @@ void FTMotion::convertToSteps(const uint32_t idx) {
730737
#else
731738
#define TOSTEPS(A,B) int32_t(trajMod.A[idx] * planner.settings.axis_steps_per_mm[B]) - steps.A
732739
xyze_long_t delta = LOGICAL_AXIS_ARRAY(
733-
TOSTEPS(e, E_AXIS_N(stepper.current_block->extruder)),
740+
TOSTEPS(e, E_AXIS_N(current_extruder_idx)),
734741
TOSTEPS(x, X_AXIS), TOSTEPS(y, Y_AXIS), TOSTEPS(z, Z_AXIS),
735742
TOSTEPS(i, I_AXIS), TOSTEPS(j, J_AXIS), TOSTEPS(k, K_AXIS),
736743
TOSTEPS(u, U_AXIS), TOSTEPS(v, V_AXIS), TOSTEPS(w, W_AXIS)

Marlin/src/module/ft_motion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class FTMotion {
169169

170170
static xyze_long_t steps;
171171

172+
static uint8_t current_extruder_idx;
173+
172174
// Shaping variables.
173175
#if HAS_FTM_SHAPING
174176

0 commit comments

Comments
 (0)