Null-terminate lcd_status_message

This commit is contained in:
Scott Lahteine 2018-02-19 10:07:22 -06:00
parent b1ec140f0b
commit f39b28b6a9

View File

@ -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);
}