Skip to content

Commit

Permalink
fix: out of bounds memory access in setValue function (opentibiabr#785)
Browse files Browse the repository at this point in the history
This fix addresses a SonarCloud warning regarding an out-of-bounds memory access in the setValue function. Specifically, it checks that the row and col values passed to the function are within the bounds of the data_ array before performing the assignment. This ensures that the program will not attempt to access memory that is outside the allocated memory block, preventing potential crashes or other errors.
  • Loading branch information
dudantas authored Jan 17, 2023
1 parent 2f252e2 commit 50963c5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/creatures/combat/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ class MatrixArea
// non-assignable
MatrixArea& operator=(const MatrixArea&) = delete;

void setValue(uint32_t row, uint32_t col, bool value) const {
data_[row][col] = value;
void setValue(uint32_t row, uint32_t col, bool value) {
if (row < rows && col < cols)
{
data_[row][col] = value;
} else {
SPDLOG_ERROR("[{}] Access exceeds the upper limit of memory block");
throw std::out_of_range("Access exceeds the upper limit of memory block");
}
}
bool getValue(uint32_t row, uint32_t col) const {
return data_[row][col];
Expand Down

0 comments on commit 50963c5

Please sign in to comment.