Skip to content

Commit 98887e8

Browse files
authored
fix memory corruption bug
1 parent 39f2386 commit 98887e8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/lib/cimb_translator/AdjacentCellFinder.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ int AdjacentCellFinder::in_row_with_margin(int index) const
4343

4444
int AdjacentCellFinder::right(int index) const
4545
{
46-
int next = index+1;
47-
if (next >= (int)_positions.size())
46+
if (index < 0 || index >= (int)_positions.size() - 1)
4847
return -1;
49-
if (_positions[next].first < _positions[index].first) // loop
48+
int next = index + 1;
49+
if (_positions[next].first < _positions[index].first)
5050
return -1;
5151
return next;
5252
}
@@ -63,16 +63,17 @@ int AdjacentCellFinder::left(int index) const
6363

6464
int AdjacentCellFinder::bottom(int index) const
6565
{
66+
if (index < 0 || index >= (int)_positions.size())
67+
return -1;
6668
int increment = _dimensions;
6769
if (in_row_with_margin(index))
6870
increment -= _markerSize;
6971
int next = index + increment;
7072
if (in_row_with_margin(next))
7173
next -= _markerSize;
72-
73-
if (next >= (int)_positions.size())
74+
if (next < 0 || next >= (int)_positions.size())
7475
return -1;
75-
if (_positions[next].first != _positions[index].first) // near anchor
76+
if (_positions[next].first != _positions[index].first)
7677
return -1;
7778
return next;
7879
}

0 commit comments

Comments
 (0)