ssilver2007 / LCD_1602_RUS_ALL

Библиотека поддержки кириллицы для дисплеев на базе контроллера HD44780 без встроенной кириллицы. Подключение дисплея как напрямую (10-контактное), так и по интерфейсу I2C.
GNU General Public License v3.0
61 stars 11 forks source link

Fixed Unicode character presence check #12

Open Voha888 opened 5 months ago

Voha888 commented 5 months ago

The check for numbers less than 128 is valid when we are dealing with single-byte values. However, a variable of type wchar_t is two bytes long, so Cyrillic characters will start somewhere from the number 1000 and above. Therefore, all values from 0 to 255 represent Latin characters, while starting from 265, they are already two-byte utf8 characters. If you accidentally truncate a string with Arduino's built-in libraries, a number higher than 128 may end up in the check, leading to a microcontroller reboot. Here's a minimal example:

String newstring = "Д";
newstring.remove(1);
lcd.print(newstring);
String newstring2 = "АБВГД";
newstring2.remove(3);
lcd.print(newstring2);

This fix allows truncated characters to be displayed properly without causing errors.