Skip to content

Commit

Permalink
Fix out of bounds access in Haar coefficients print method
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Sep 16, 2024
1 parent 62a9713 commit 450d9ae
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ struct HaarCoefficients {
return *this;
}
std::string toString() const {
// TODO(victorr): Check if the order of the labels matches the transform's
// implementation
std::stringstream ss;
ss << "[";
for (int coeff_idx = 1; coeff_idx <= kNumDetailCoefficients;
++coeff_idx) {
for (int dim_idx = 0; dim_idx < kDim; ++dim_idx) {
ss << (bit_ops::is_bit_set(coeff_idx, dim_idx) ? "H" : "L");
}
ss << " = " << this->operator[](coeff_idx) << ", ";
ss << " = " << this->operator[](coeff_idx - 1) << ", ";
}
ss << "\b\b]";
return ss.str();
Expand Down Expand Up @@ -104,14 +102,14 @@ struct HaarCoefficients {
return {lhs.scale + rhs.scale, lhs.details + rhs.details};
}
Parent& operator+=(const Parent& rhs) {
*this = *this + rhs.coefficients;
*this = *this + rhs;
return *this;
}
friend Parent operator-(const Parent& lhs, const Parent& rhs) {
return {lhs.scale - rhs.scale, lhs.details - rhs.details};
}
Parent& operator-=(const Parent& rhs) {
*this = *this - rhs.coefficients;
*this = *this - rhs;
return *this;
}
friend Parent operator*(ValueType lhs, const Parent& rhs) {
Expand Down

0 comments on commit 450d9ae

Please sign in to comment.