1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-27 13:56:24 +00:00

Null-terminate lcd_status_message

This commit is contained in:
Scott Lahteine 2018-02-19 10:09:08 -06:00
parent a11fcd46a2
commit 25e3e62354

View File

@ -5172,6 +5172,7 @@ void lcd_update() {
inline void pad_message_string() { inline void pad_message_string() {
uint8_t i = 0, j = 0; uint8_t i = 0, j = 0;
char c; char c;
lcd_status_message[MAX_MESSAGE_LENGTH] = '\0';
while ((c = lcd_status_message[i]) && j < LCD_WIDTH) { while ((c = lcd_status_message[i]) && j < LCD_WIDTH) {
if (PRINTABLE(c)) j++; if (PRINTABLE(c)) j++;
i++; i++;
@ -5221,7 +5222,7 @@ bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
void lcd_setstatus(const char * const message, const bool persist) { void lcd_setstatus(const char * const message, const bool persist) {
if (lcd_status_message_level > 0) return; 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); lcd_finishstatus(persist);
} }
@ -5229,7 +5230,7 @@ void lcd_setstatusPGM(const char * const message, int8_t level) {
if (level < 0) level = lcd_status_message_level = 0; if (level < 0) level = lcd_status_message_level = 0;
if (level < lcd_status_message_level) return; if (level < lcd_status_message_level) return;
lcd_status_message_level = level; 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); lcd_finishstatus(level > 0);
} }
@ -5238,7 +5239,7 @@ void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) {
lcd_status_message_level = level; lcd_status_message_level = level;
va_list args; va_list args;
va_start(args, fmt); 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); va_end(args);
lcd_finishstatus(level > 0); lcd_finishstatus(level > 0);
} }