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.
This commit is contained in:
Matthijs Kooijman 2013-12-18 12:34:44 +01:00
parent 3fdda81a1a
commit 1786716a75
1 changed files with 4 additions and 0 deletions

View File

@ -182,6 +182,10 @@ void LiquidCrystal::home()
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
const size_t max_lines = sizeof(_row_offsets) / sizeof(*_row_offsets);
if ( row >= max_lines ) {
row = max_lines - 1; // we count rows starting w/0
}
if ( row >= _numlines ) {
row = _numlines - 1; // we count rows starting w/0
}