[tm1638][rp2040_pio_led_strip][atm90e32] Fix bounds checks and off-by-one (#14559)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan SwobodaandClaude Opus 4.6 authored and GitHub committed 2026-03-06 09:00:46 -10:00
1 parent 8a915dcbbe
commit 9654140c00
3 files changed
+19 -16

No files matched your search

+16 -13
View File
@@ -147,35 +147,38 @@ void TM1638Component::set_intensity(uint8_t brightness_level) {
uint8_t TM1638Component::print(uint8_t start_pos, const char *str) {
uint8_t pos = start_pos;
bool last_was_dot = false;
for (; *str != '\0'; str++) {
uint8_t data = TM1638_UNKNOWN_CHAR;
if (*str >= ' ' && *str <= '~') {
data = progmem_read_byte(&TM1638Translation::SEVEN_SEG[*str - 32]); // subract 32 to account for ASCII offset
} else if (data == TM1638_UNKNOWN_CHAR) {
// Subtract 32 to account for ASCII offset
data = progmem_read_byte(&TM1638Translation::SEVEN_SEG[*str - 32]);
} else {
ESP_LOGW(TAG, "Encountered character '%c' with no TM1638 representation while translating string!", *str);
}
if (*str == '.') // handle dots
{
if (pos != start_pos &&
!last_was_dot) // if we are not at the first position, backup by one unless last char was a dot
{
if (*str == '.') {
// Merge dot onto previous character unless we're at the start or last was also a dot
if (pos != start_pos && !last_was_dot) {
pos--;
}
this->buffer_[pos] |= 0b10000000; // turn on the dot on the previous position
last_was_dot = true; // set a bit in case the next chracter is also a dot
} else // if not a dot, then just write the character to display
{
if (pos >= 8) {
ESP_LOGI(TAG, "TM1638 String is too long for the display!");
break;
}
// Turn on the dot on the previous position
this->buffer_[pos] |= 0b10000000;
last_was_dot = true;
} else {
// Not a dot, write the character to display
if (pos >= 8) {
ESP_LOGI(TAG, "TM1638 String is too long for the display!");
break;
}
this->buffer_[pos] = data;
last_was_dot = false; // clear dot tracking bit
last_was_dot = false;
}
pos++;