diff --git a/esphome/components/tuya/light/tuya_light.cpp b/esphome/components/tuya/light/tuya_light.cpp index c487f9f50b..097b3c1af8 100644 --- a/esphome/components/tuya/light/tuya_light.cpp +++ b/esphome/components/tuya/light/tuya_light.cpp @@ -191,7 +191,7 @@ void TuyaLight::write_state(light::LightState *state) { case TuyaColorType::RGB: { char buffer[7]; const char *format_str = this->color_type_lowercase_ ? "%02x%02x%02x" : "%02X%02X%02X"; - sprintf(buffer, format_str, int(red * 255), int(green * 255), int(blue * 255)); + snprintf(buffer, sizeof(buffer), format_str, int(red * 255), int(green * 255), int(blue * 255)); color_value = buffer; break; } @@ -201,7 +201,7 @@ void TuyaLight::write_state(light::LightState *state) { rgb_to_hsv(red, green, blue, hue, saturation, value); char buffer[13]; const char *format_str = this->color_type_lowercase_ ? "%04x%04x%04x" : "%04X%04X%04X"; - sprintf(buffer, format_str, hue, int(saturation * 1000), int(value * 1000)); + snprintf(buffer, sizeof(buffer), format_str, hue, int(saturation * 1000), int(value * 1000)); color_value = buffer; break; } @@ -211,8 +211,8 @@ void TuyaLight::write_state(light::LightState *state) { rgb_to_hsv(red, green, blue, hue, saturation, value); char buffer[15]; const char *format_str = this->color_type_lowercase_ ? "%02x%02x%02x%04x%02x%02x" : "%02X%02X%02X%04X%02X%02X"; - sprintf(buffer, format_str, int(red * 255), int(green * 255), int(blue * 255), hue, int(saturation * 255), - int(value * 255)); + snprintf(buffer, sizeof(buffer), format_str, int(red * 255), int(green * 255), int(blue * 255), hue, + int(saturation * 255), int(value * 255)); color_value = buffer; break; }