🩹 Fix string buffer warning (#26550)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Dennis
2023-12-24 22:40:20 -05:00
committed by GitHub
parent 89fdfcfaf9
commit bb557e5195
5 changed files with 27 additions and 26 deletions

View File

@@ -136,7 +136,7 @@ public:
MString& setn(FSTR_P const f, int len) { return setn_P(FTOP(f), len); } MString& setn(FSTR_P const f, int len) { return setn_P(FTOP(f), len); }
// set(repchr_t('-', 10)) // set(repchr_t('-', 10))
MString& set(const repchr_t &s) { int c = _MIN(s.count, SIZE); memset(str, s.asc, c); str[c] = '\0'; debug(F("")); return *this; } MString& set(const repchr_t &s) { int c = _MIN(s.count, SIZE); if (c >= 0) { if (c > 0) memset(str, s.asc, c); str[c] = '\0'; } debug(F("repchr_t")); return *this; }
// set(spaces_t(10)) // set(spaces_t(10))
MString& set(const spaces_t &s) { repchr_t r(' ', s.count); return set(r); } MString& set(const spaces_t &s) { repchr_t r(' ', s.count); return set(r); }

View File

@@ -309,10 +309,10 @@ typedef struct WFloat { float value; char width; char prec;
typedef struct PFloat { float value; char prec; typedef struct PFloat { float value; char prec;
PFloat(float v, char p) : value(v), prec(p) {} PFloat(float v, char p) : value(v), prec(p) {}
} p_float_t; } p_float_t;
typedef struct RepChr { char asc; uint8_t count; typedef struct RepChr { char asc; int8_t count;
RepChr(char a, uint8_t c) : asc(a), count(c) {} RepChr(char a, uint8_t c) : asc(a), count(c) {}
} repchr_t; } repchr_t;
typedef struct Spaces { uint8_t count; typedef struct Spaces { int8_t count;
Spaces(uint8_t c) : count(c) {} Spaces(uint8_t c) : count(c) {}
} spaces_t; } spaces_t;

View File

@@ -479,16 +479,16 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
// Prepare strings for progress display // Prepare strings for progress display
#if ANY(HAS_EXTRA_PROGRESS, HAS_PRINT_PROGRESS) #if ANY(HAS_EXTRA_PROGRESS, HAS_PRINT_PROGRESS)
static MarlinUI::progress_t progress = 0; static MarlinUI::progress_t progress = 0;
static MString<12> progressString; static MString<13> progressString;
#endif #endif
#if HAS_EXTRA_PROGRESS #if HAS_EXTRA_PROGRESS
#if HAS_TIME_DISPLAY #if HAS_TIME_DISPLAY
static void prepare_time_string(const duration_t &time, char prefix) { static void prepare_time_string(const duration_t &time, char prefix) {
char str[10]; char str[13];
const uint8_t time_len = time.toDigital(str, time.value >= 60*60*24L); // 5 to 8 chars const uint8_t time_len = time.toDigital(str, time.value >= 60*60*24L); // 5 to 8 chars
progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces
} }
#endif #endif
#if ENABLED(SHOW_PROGRESS_PERCENT) #if ENABLED(SHOW_PROGRESS_PERCENT)

View File

@@ -662,39 +662,36 @@ bool ST7920_Lite_Status_Screen::indicators_changed() {
// Process progress strings // Process progress strings
#if HAS_PRINT_PROGRESS #if HAS_PRINT_PROGRESS
static char screenstr[8]; static MString<8> screenstr;
#if HAS_TIME_DISPLAY #if HAS_TIME_DISPLAY
char * ST7920_Lite_Status_Screen::prepare_time_string(const duration_t &time, char prefix) { char * ST7920_Lite_Status_Screen::prepare_time_string(const duration_t &time, char prefix) {
static char str[6]; static char time_str[6];
memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts, not doing right-justification to save cycles (void)time.toDigital(time_str); // Up to 5 chars
screenstr[0] = prefix; screenstr = prefix;
TERN_(HOTENDS == 1, screenstr[1] = 0x07;) // add bullet • separator when there is space if (HOTENDS == 1) screenstr += char(0x07); // Add bullet • separator when there is space
int str_length = time.toDigital(str); screenstr += time_str;
memcpy(&screenstr[TERN(HOTENDS == 1, 2, 1)], str, str_length); //memcpy because we can't have terminator screenstr += Spaces(3);
return screenstr; return &screenstr;
} }
#endif #endif
void ST7920_Lite_Status_Screen::draw_progress_string(uint8_t addr, const char *str) { void ST7920_Lite_Status_Screen::draw_progress_string(uint8_t addr, const char *str) {
set_ddram_address(addr); set_ddram_address(addr);
begin_data(); begin_data();
write_str(str, TERN(HOTENDS == 1, 8, 6)); write_str(str, HOTENDS == 1 ? 8 : 6);
} }
#define PPOS (DDRAM_LINE_3 + TERN(HOTENDS == 1, 4, 5)) // progress string position, in 16-bit words constexpr uint8_t PPOS = (DDRAM_LINE_3 + (HOTENDS == 1 ? 4 : 5)); // Progress string position, in 16-bit words
#if ENABLED(SHOW_PROGRESS_PERCENT) #if ENABLED(SHOW_PROGRESS_PERCENT)
void MarlinUI::drawPercent() { lightUI.drawPercent(); } void MarlinUI::drawPercent() { lightUI.drawPercent(); }
void ST7920_Lite_Status_Screen::drawPercent() { void ST7920_Lite_Status_Screen::drawPercent() {
#define LSHIFT TERN(HOTENDS == 1, 0, 1)
const uint8_t progress = ui.get_progress_percent(); const uint8_t progress = ui.get_progress_percent();
memset(&screenstr, ' ', 8); // fill with spaces to avoid artifacts if (progress) {
if (progress){ screenstr += Spaces(1 + (HOTENDS == 1));
memcpy(&screenstr[2 - LSHIFT], \ screenstr += TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress));
TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)), \ screenstr += "% ";
TERN(PRINT_PROGRESS_SHOW_DECIMALS, 4, 3));
screenstr[(TERN(PRINT_PROGRESS_SHOW_DECIMALS, 6, 5) - LSHIFT)] = '%';
draw_progress_string(PPOS, screenstr); draw_progress_string(PPOS, screenstr);
} }
} }

View File

@@ -1035,9 +1035,13 @@ void MarlinUI::init() {
uint8_t abs_diff = ABS(encoderDiff); uint8_t abs_diff = ABS(encoderDiff);
#if ENCODER_PULSES_PER_STEP > 1 #if ENCODER_PULSES_PER_STEP > 1
static int8_t lastEncoderDiff; #if HAS_TOUCH_SLEEP
TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen()); static int8_t lastEncoderDiff;
lastEncoderDiff = encoderDiff; if (lastEncoderDiff != encoderDiff) {
wakeup_screen();
lastEncoderDiff = encoderDiff;
}
#endif
#endif #endif
const bool encoderPastThreshold = (abs_diff >= epps); const bool encoderPastThreshold = (abs_diff >= epps);