potential bugs that warning=everything caught

This commit is contained in:
2026-07-02 01:11:44 +02:00
parent a0bbc71cd8
commit 1d2095261f

View File

@@ -72,7 +72,7 @@ void lcd_write_buf(struct lcd_t *lcd, const uint8_t row, const uint8_t col, cons
len++;
len = MIN(len, sizeof(lcd->writebuf) - col);
uint8_t pos = 4 + col + (LCD_COLS * (row % 2)); // skip 4 bytes to leave room for set cursor command
int pos = 4 + col + (LCD_COLS * (row % 2)); // skip 4 bytes to leave room for set cursor command
if (row >= 2)
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
memcpy(lcd->writebuf.text + pos, str, len);
@@ -80,21 +80,21 @@ void lcd_write_buf(struct lcd_t *lcd, const uint8_t row, const uint8_t col, cons
/* hyperoptimized function to write a formatted string to lcd buffer. */
/* we cant just snprintf to the buffer directly bc it null terminates */
inline void lcd_writef(struct lcd_t *lcd, const uint8_t x, const uint8_t y, const char *fmt, ...) {
void lcd_writef(struct lcd_t *lcd, const uint8_t x, const uint8_t y, const char *fmt, ...) {
char tmp[LCD_COLS + 1];
va_list ap;
va_start(ap, fmt);
uint8_t len = vsnprintf(tmp, sizeof(tmp), fmt, ap); // print fmt and ap to a temporary buffer
va_end(ap);
len = MIN(len, LCD_COLS - x);
uint8_t pos = 4 + x + (LCD_COLS * (y % 2)); // skip 4 bytes to leave room for set cursor command
int pos = 4 + x + (LCD_COLS * (y % 2)); // skip 4 bytes to leave room for set cursor command
if (y >= 2)
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
memcpy(lcd->writebuf.text + pos, tmp, len); // copy to lcd writebuffer address + whatever pos is
}
inline void lcd_clear_buf(struct lcd_t *lcd) {
memset(lcd->writebuf.text, ' ', sizeof(lcd->writebuf));
memset(lcd->writebuf.text, ' ', sizeof(lcd->writebuf.text));
}
/* flushes writebuffer to lcd, hyperoptmized, flushes buffer and commands in a single write operation */