Skip to content

Commit

Permalink
fix memory corruption bug
Browse files Browse the repository at this point in the history
  • Loading branch information
notune authored and sz3 committed Feb 8, 2024
1 parent 0fe367f commit ead73ea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib/cimb_translator/AdjacentCellFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ int AdjacentCellFinder::in_row_with_margin(int index) const

int AdjacentCellFinder::right(int index) const
{
int next = index+1;
if (next >= (int)_positions.size())
if (index < 0 || index >= (int)_positions.size() - 1)
return -1;
if (_positions[next].first < _positions[index].first) // loop
int next = index + 1;
if (_positions[next].first < _positions[index].first)
return -1;
return next;
}
Expand All @@ -63,16 +63,17 @@ int AdjacentCellFinder::left(int index) const

int AdjacentCellFinder::bottom(int index) const
{
if (index < 0 || index >= (int)_positions.size())
return -1;
int increment = _dimensions;
if (in_row_with_margin(index))
increment -= _markerSize;
int next = index + increment;
if (in_row_with_margin(next))
next -= _markerSize;

if (next >= (int)_positions.size())
if (next < 0 || next >= (int)_positions.size())
return -1;
if (_positions[next].first != _positions[index].first) // near anchor
if (_positions[next].first != _positions[index].first)
return -1;
return next;
}
Expand Down

0 comments on commit ead73ea

Please sign in to comment.