From 299606e4ae7b896d1febc2f45cfafb5e7958bc99 Mon Sep 17 00:00:00 2001 From: GMagician <3684609+GMagician@users.noreply.github.com> Date: Sat, 10 Feb 2018 21:14:34 +0100 Subject: [PATCH] [2.0.x] Memory overflow protection (#9562) --- Marlin/src/lcd/ultralcd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index d5b439e904..220955c81a 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -92,7 +92,7 @@ uint8_t lcd_status_update_delay = 1, // First update one loop delayed lcd_status_message_level; // Higher level blocks lower level #if ENABLED(STATUS_MESSAGE_SCROLLING) - #define MAX_MESSAGE_LENGTH max(2 * CHARSIZE * LCD_WIDTH, LONG_FILENAME_LENGTH) + #define MAX_MESSAGE_LENGTH max(CHARSIZE * 2 * (LCD_WIDTH), LONG_FILENAME_LENGTH) uint8_t status_scroll_pos = 0; #else #define MAX_MESSAGE_LENGTH CHARSIZE * (LCD_WIDTH) @@ -5218,7 +5218,7 @@ bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); } void lcd_setstatus(const char * const message, const bool persist) { if (lcd_status_message_level > 0) return; - strncpy(lcd_status_message, message, 3 * (LCD_WIDTH)); + strncpy(lcd_status_message, message, COUNT(lcd_status_message) - 1); lcd_finishstatus(persist); } @@ -5226,7 +5226,7 @@ void lcd_setstatusPGM(const char * const message, int8_t level) { if (level < 0) level = lcd_status_message_level = 0; if (level < lcd_status_message_level) return; lcd_status_message_level = level; - strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH)); + strncpy_P(lcd_status_message, message, COUNT(lcd_status_message) - 1); lcd_finishstatus(level > 0); } @@ -5235,7 +5235,7 @@ void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) { lcd_status_message_level = level; va_list args; va_start(args, fmt); - vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args); + vsnprintf_P(lcd_status_message, COUNT(lcd_status_message) - 1, fmt, args); va_end(args); lcd_finishstatus(level > 0); }