From f39b28b6a90fa0b340927fa7de353c39f8bc4fd6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 19 Feb 2018 10:07:22 -0600 Subject: [PATCH] Null-terminate lcd_status_message --- Marlin/ultralcd.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index d3dbe5a0b6..f9075abf64 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -5157,6 +5157,7 @@ void lcd_update() { inline void pad_message_string() { uint8_t i = 0, j = 0; char c; + lcd_status_message[MAX_MESSAGE_LENGTH] = '\0'; while ((c = lcd_status_message[i]) && j < LCD_WIDTH) { if (PRINTABLE(c)) j++; i++; @@ -5206,7 +5207,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, COUNT(lcd_status_message) - 1); + strncpy(lcd_status_message, message, MAX_MESSAGE_LENGTH); lcd_finishstatus(persist); } @@ -5214,7 +5215,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, COUNT(lcd_status_message) - 1); + strncpy_P(lcd_status_message, message, MAX_MESSAGE_LENGTH); lcd_finishstatus(level > 0); } @@ -5223,7 +5224,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, COUNT(lcd_status_message) - 1, fmt, args); + vsnprintf_P(lcd_status_message, MAX_MESSAGE_LENGTH, fmt, args); va_end(args); lcd_finishstatus(level > 0); }