diff --git a/esphome/components/sml/sml_parser.cpp b/esphome/components/sml/sml_parser.cpp index 85e5a2da03..16e37949dc 100644 --- a/esphome/components/sml/sml_parser.cpp +++ b/esphome/components/sml/sml_parser.cpp @@ -104,7 +104,10 @@ std::vector SmlFile::get_obis_info() { std::string bytes_repr(const BytesView &buffer) { std::string repr; for (auto const value : buffer) { - repr += str_sprintf("%02x", value & 0xff); + // max 3: 2 hex digits + null + char hex_buf[3]; + snprintf(hex_buf, sizeof(hex_buf), "%02x", static_cast(value)); + repr += hex_buf; } return repr; } @@ -146,7 +149,11 @@ ObisInfo::ObisInfo(const BytesView &server_id, const SmlNode &val_list_entry) : } std::string ObisInfo::code_repr() const { - return str_sprintf("%d-%d:%d.%d.%d", this->code[0], this->code[1], this->code[2], this->code[3], this->code[4]); + // max 20: "255-255:255.255.255" (19 chars) + null + char buf[20]; + snprintf(buf, sizeof(buf), "%d-%d:%d.%d.%d", this->code[0], this->code[1], this->code[2], this->code[3], + this->code[4]); + return buf; } } // namespace sml