diff --git a/esphome/components/lvgl/lvgl_esphome.cpp b/esphome/components/lvgl/lvgl_esphome.cpp index 685a0920ea..bb373abb88 100644 --- a/esphome/components/lvgl/lvgl_esphome.cpp +++ b/esphome/components/lvgl/lvgl_esphome.cpp @@ -65,9 +65,9 @@ std::string lv_event_code_name_for(uint8_t event_code) { if (event_code < sizeof(EVENT_NAMES) / sizeof(EVENT_NAMES[0])) { return EVENT_NAMES[event_code]; } - // max 4 bytes: "%2d" with uint8_t (max 255, 3 digits) + null + // max 4 bytes: "%u" with uint8_t (max 255, 3 digits) + null char buf[4]; - snprintf(buf, sizeof(buf), "%2d", event_code); + snprintf(buf, sizeof(buf), "%u", event_code); return buf; } diff --git a/esphome/components/statsd/statsd.cpp b/esphome/components/statsd/statsd.cpp index 7729f36858..c4b49a09a9 100644 --- a/esphome/components/statsd/statsd.cpp +++ b/esphome/components/statsd/statsd.cpp @@ -114,14 +114,23 @@ void StatsdComponent::update() { // This implies you can't explicitly set a gauge to a negative number without first setting it to zero. if (val < 0) { if (this->prefix_) { - out.append(str_sprintf("%s.", this->prefix_)); + out.append(this->prefix_); + out.append("."); } - out.append(str_sprintf("%s:0|g\n", s.name)); + out.append(s.name); + out.append(":0|g\n"); } if (this->prefix_) { - out.append(str_sprintf("%s.", this->prefix_)); + out.append(this->prefix_); + out.append("."); } - out.append(str_sprintf("%s:%f|g\n", s.name, val)); + out.append(s.name); + // Buffer for ":" + value + "|g\n". + // %g uses max 13 chars for value (sign + 6 significant digits + e+xxx) + // Total: 1 + 13 + 4 = 18 chars + null, use 24 for safety + char val_buf[24]; + snprintf(val_buf, sizeof(val_buf), ":%g|g\n", val); + out.append(val_buf); if (out.length() > SEND_THRESHOLD) { this->send_(&out);