Skip to content

Commit 1786716

Browse files
In LiquidCrystal::setCursor(), check against length of _row_offsets as well
Before, the row value was maximized against _numlines already, but the value from _numlines is not limited anywhere, so it could be longer than the length of _row_offsets. This check makes sure the array bounds is never exceeded.
1 parent 3fdda81 commit 1786716

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libraries/LiquidCrystal/src/LiquidCrystal.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ void LiquidCrystal::home()
182182

183183
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
184184
{
185+
const size_t max_lines = sizeof(_row_offsets) / sizeof(*_row_offsets);
186+
if ( row >= max_lines ) {
187+
row = max_lines - 1; // we count rows starting w/0
188+
}
185189
if ( row >= _numlines ) {
186190
row = _numlines - 1; // we count rows starting w/0
187191
}

0 commit comments

Comments
 (0)