Fix possible overflow in matrix debug formatting

This commit is contained in:
Owen Brooks 2022-06-17 18:41:53 +10:00
parent 364302d072
commit e70bcdbe22
1 changed files with 13 additions and 12 deletions

View File

@ -203,20 +203,21 @@ impl<T: fmt::Debug, R: Dim, C: Dim, S: RawStorage<T, R, C> + fmt::Debug> fmt::De
writeln!(f, "")?; writeln!(f, "")?;
} }
write!(f, "[")?; write!(f, "[")?;
let nrows = self.nrows();
let ncols = self.ncols(); let row_separator = match f.alternate() {
for i in 0..nrows { true => ";\n ",
for j in 0..ncols { false => "; ",
if j != 0 { };
for (i, row) in self.row_iter().enumerate() {
if i > 0 {
write!(f, "{row_separator}")?;
}
for (j, element) in row.iter().enumerate() {
if j > 0 {
write!(f, ", ")?; write!(f, ", ")?;
} }
self[(i, j)].fmt(f)?; element.fmt(f)?;
}
if i != nrows - 1 {
write!(f, "; ")?;
}
if f.alternate() && i != nrows - 1 {
write!(f, "\n ")?;
} }
} }
write!(f, "]") write!(f, "]")