Skip to content

Commit

Permalink
🐛 Fix bool evalution of XYval and similar types (MarlinFirmware#26936)
Browse files Browse the repository at this point in the history
Require explicit cast to get T* pointers from XYval and similar types. This prevents the pointer from being implicitly returned and checked for nullptr when trying to evaluate these structs in boolean expressions.
  • Loading branch information
sjasonsmith authored Apr 6, 2024
1 parent 17dfe8e commit d30fcb8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ struct XYval {
// Length reduced to one dimension
FI constexpr T magnitude() const { return (T)sqrtf(x*x + y*y); }
// Pointer to the data as a simple array
FI operator T* () { return pos; }
explicit FI operator T* () { return pos; }
// If any element is true then it's true
FI constexpr operator bool() const { return x || y; }
// Smallest element
Expand Down Expand Up @@ -599,7 +599,7 @@ struct XYZval {
// Length reduced to one dimension
FI constexpr T magnitude() const { return (T)TERN(HAS_X_AXIS, sqrtf(NUM_AXIS_GANG(x*x, + y*y, + z*z, + i*i, + j*j, + k*k, + u*u, + v*v, + w*w)), 0); }
// Pointer to the data as a simple array
FI operator T* () { return pos; }
explicit FI operator T* () { return pos; }
// If any element is true then it's true
FI constexpr operator bool() const { return 0 NUM_AXIS_GANG(|| x, || y, || z, || i, || j, || k, || u, || v, || w); }
// Smallest element
Expand Down Expand Up @@ -747,7 +747,7 @@ struct XYZEval {
// Length reduced to one dimension
FI constexpr T magnitude() const { return (T)sqrtf(LOGICAL_AXIS_GANG(+ e*e, + x*x, + y*y, + z*z, + i*i, + j*j, + k*k, + u*u, + v*v, + w*w)); }
// Pointer to the data as a simple array
FI operator T* () { return pos; }
explicit FI operator T* () { return pos; }
// If any element is true then it's true
FI constexpr operator bool() const { return 0 LOGICAL_AXIS_GANG(|| e, || x, || y, || z, || i, || j, || k, || u, || v, || w); }
// Smallest element
Expand Down

0 comments on commit d30fcb8

Please sign in to comment.