forked from mirrors/qmk_userspace
Fix out of bound OLED font access (#8145)
* Fix out of bound OLED font access The default font is 1344 bytes, or a total of 224 glyphs (each 6-bytes wide). OLED_FONT_END defaults to 224, which if used will then index off the end of the font array. So either the documentation or code is wrong. Instead of figuring out the rewording of the documentation, just change the OLED_FONT_END default value to 223, to match the documentation and code. * Add static assert to check array size Build bomb if the font array size doesn't match to the defines.
This commit is contained in:
parent
78e060f55a
commit
9456832a3b
3 changed files with 6 additions and 4 deletions
|
@ -392,6 +392,8 @@ void oled_write_char(const char data, bool invert) {
|
|||
static uint8_t oled_temp_buffer[OLED_FONT_WIDTH];
|
||||
memcpy(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH);
|
||||
|
||||
_Static_assert(sizeof(font) >= ((OLED_FONT_END + 1 - OLED_FONT_START) * OLED_FONT_WIDTH), "OLED_FONT_END references outside array");
|
||||
|
||||
// set the reder buffer data
|
||||
uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
|
||||
if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) {
|
||||
|
@ -585,4 +587,4 @@ void oled_task(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
__attribute__((weak)) void oled_task_user(void) {}
|
||||
__attribute__((weak)) void oled_task_user(void) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue