Skip to content

Commit

Permalink
util: Fix out of bounds access in matrix constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Oct 9, 2023
1 parent 4002db5 commit 52058a1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libopenage/util/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ class Matrix : public std::array<std::array<T, N>, M> {
static_assert(sizeof...(args) == N * M, "not all values supplied");

std::array<float, N * M> temp{{static_cast<T>(args)...}};
for (size_t i = 0; i < N * M; i++) {
(*this)[i / (N * M)][i % (N * M)] = temp[i];
size_t index = 0;
for (size_t row = 0; row < M; row++) {
for (size_t col = 0; col < N; col++) {
(*this)[row][col] = temp[index];
index += 1;
}
}
}

Expand Down

0 comments on commit 52058a1

Please sign in to comment.