From a7968c754d9b004136454ed573a736c03b9037b6 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sun, 28 Apr 2019 12:36:31 +1200 Subject: [PATCH] prevent max7456 screen_buffer from overflow (#8063) prevent max7456 screen_buffer from overflow --- src/main/drivers/max7456.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/drivers/max7456.c b/src/main/drivers/max7456.c index 28788c9947..578e33e3a5 100644 --- a/src/main/drivers/max7456.c +++ b/src/main/drivers/max7456.c @@ -571,14 +571,16 @@ uint8_t* max7456GetScreenBuffer(void) void max7456WriteChar(uint8_t x, uint8_t y, uint8_t c) { - screenBuffer[y*CHARS_PER_LINE+x] = c; + if (x < CHARS_PER_LINE && y < VIDEO_LINES_PAL) { + screenBuffer[y * CHARS_PER_LINE + x] = c; + } } void max7456Write(uint8_t x, uint8_t y, const char *buff) { - for (int i = 0; *(buff+i); i++) { - if (x+i < CHARS_PER_LINE) {// Do not write over screen - screenBuffer[y*CHARS_PER_LINE+x+i] = *(buff+i); + if (y < VIDEO_LINES_PAL) { + for (int i = 0; buff[i] && x + i < CHARS_PER_LINE; i++) { + screenBuffer[y * CHARS_PER_LINE + x + i] = buff[i]; } } }