Prevent out of bounds custom character font data

This commit is contained in:
Alex Voinea 2023-09-30 12:57:09 +02:00
parent 9dbbb12a13
commit 8a39f53e26
1 changed files with 6 additions and 5 deletions

View File

@ -82,6 +82,11 @@ uint8_t lcd_escape[8];
#endif #endif
static uint8_t lcd_custom_characters[8] = {0}; static uint8_t lcd_custom_characters[8] = {0};
static const CustomCharacter Font[] PROGMEM = {
#include "FontTable.h"
};
#define CUSTOM_CHARACTERS_CNT (sizeof(Font) / sizeof(Font[0]))
static void lcd_display(void); static void lcd_display(void);
@ -154,7 +159,7 @@ static void lcd_write(uint8_t value)
if (lcd_currline > 3) lcd_currline = -1; if (lcd_currline > 3) lcd_currline = -1;
lcd_set_cursor(0, lcd_currline + 1); // LF lcd_set_cursor(0, lcd_currline + 1); // LF
} }
else if ((value >= 0x80) && (value <= 0xDF)) { else if ((value >= 0x80) && (value < (0x80 + CUSTOM_CHARACTERS_CNT))) {
lcd_print_custom(value); lcd_print_custom(value);
} }
#ifdef VT100 #ifdef VT100
@ -857,10 +862,6 @@ void lcd_buttons_update(void)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Custom character data // Custom character data
const CustomCharacter Font[] PROGMEM = {
#include "FontTable.h"
};
// #define DEBUG_CUSTOM_CHARACTERS // #define DEBUG_CUSTOM_CHARACTERS
static void lcd_print_custom(uint8_t c) { static void lcd_print_custom(uint8_t c) {