Fix index handling in mismatch branch to remove side effects and improve maintainability#45
Conversation
liboctave/array/Array-base.cc
Outdated
| // Bounds check before accessing rhdv | ||
| if (j < rhdvl) | ||
| { | ||
| bool rhs_is_empty = (rhdv[j] == 0); // safe access |
There was a problem hiding this comment.
Any reason that you changed this from operator() to operator[]?
There was a problem hiding this comment.
I switched from operator() to operator[] because in this context rhdv is already guaranteed to be a flat array, and the explicit bounds check if (j < rhdvl) ensures safe access. Using operator[] avoids the extra overhead of operator() while still maintaining correctness. If consistency with the rest of the codebase is preferred, I can revert to operator().
There was a problem hiding this comment.
Ok. I see.
To be honest, I can't recall the reason for that. But if dimension checks can be skipped, typically the xelem member function is used in Octave. Maybe, that could be done here, too.
There was a problem hiding this comment.
I’ve updated the code to use xelem(j) as suggested. This provides raw, efficient access after the explicit bounds check and aligns with Octave’s coding style. Please let me know if further adjustments are needed.
f53573d to
dd54b2f
Compare
|
501a95e to
dd54b2f
Compare
|







This patch addresses a maintainability issue in liboctave/array/Array-base.cc
where the index variable
jwas incremented inside the right-hand operand ofa logical && operator, introducing side effects and violating MISRA/CERT guidelines.
Changes introduced:
j = 0before reuse in the mismatch branch.rhdv.rhs_is_emptyfor clarity.Impact: