From 1786716a75c5d029cc7ee43478ff5506a5cfdf85 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 18 Dec 2013 12:34:44 +0100 Subject: [PATCH] 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. --- libraries/LiquidCrystal/src/LiquidCrystal.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/LiquidCrystal/src/LiquidCrystal.cpp b/libraries/LiquidCrystal/src/LiquidCrystal.cpp index 5dbb830f9..27b53772f 100644 --- a/libraries/LiquidCrystal/src/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/src/LiquidCrystal.cpp @@ -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 }