use NOLINTBEGIN/NOLINTEND for the multi occ cases

This commit is contained in:
J. Nick Koston 2025-07-14 11:30:43 -10:00
parent d6e05061f8
commit 1778776b73
No known key found for this signature in database
4 changed files with 12 additions and 22 deletions

View File

@ -26,18 +26,15 @@ struct SpiRamAllocator : ArduinoJson::Allocator {
}; };
std::string build_json(const json_build_t &f) { std::string build_json(const json_build_t &f) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
auto doc_allocator = SpiRamAllocator(); auto doc_allocator = SpiRamAllocator();
JsonDocument json_document(&doc_allocator); JsonDocument json_document(&doc_allocator);
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
if (json_document.overflowed()) { if (json_document.overflowed()) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document!"); ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
return "{}"; return "{}";
} }
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonObject root = json_document.to<JsonObject>(); JsonObject root = json_document.to<JsonObject>();
f(root); f(root);
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
if (json_document.overflowed()) { if (json_document.overflowed()) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document!"); ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
return "{}"; return "{}";
@ -45,18 +42,17 @@ std::string build_json(const json_build_t &f) {
std::string output; std::string output;
serializeJson(json_document, output); serializeJson(json_document, output);
return output; return output;
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
bool parse_json(const std::string &data, const json_parse_t &f) { bool parse_json(const std::string &data, const json_parse_t &f) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
auto doc_allocator = SpiRamAllocator(); auto doc_allocator = SpiRamAllocator();
JsonDocument json_document(&doc_allocator); JsonDocument json_document(&doc_allocator);
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
if (json_document.overflowed()) { if (json_document.overflowed()) {
ESP_LOGE(TAG, "Could not allocate memory for JSON document!"); ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
return false; return false;
} }
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
DeserializationError err = deserializeJson(json_document, data); DeserializationError err = deserializeJson(json_document, data);
JsonObject root = json_document.as<JsonObject>(); JsonObject root = json_document.as<JsonObject>();
@ -69,6 +65,7 @@ bool parse_json(const std::string &data, const json_parse_t &f) {
} }
ESP_LOGE(TAG, "Parse error: %s", err.c_str()); ESP_LOGE(TAG, "Parse error: %s", err.c_str());
return false; return false;
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
} // namespace json } // namespace json

View File

@ -92,7 +92,7 @@ void MQTTClientComponent::send_device_info_() {
std::string topic = "esphome/discover/"; std::string topic = "esphome/discover/";
topic.append(App.get_name()); topic.append(App.get_name());
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
this->publish_json( this->publish_json(
topic, topic,
[](JsonObject root) { [](JsonObject root) {
@ -103,7 +103,6 @@ void MQTTClientComponent::send_device_info_() {
index++; index++;
} }
} }
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root["name"] = App.get_name(); root["name"] = App.get_name();
if (!App.get_friendly_name().empty()) { if (!App.get_friendly_name().empty()) {
root["friendly_name"] = App.get_friendly_name(); root["friendly_name"] = App.get_friendly_name();
@ -149,6 +148,7 @@ void MQTTClientComponent::send_device_info_() {
#endif #endif
}, },
2, this->discovery_info_.retain); 2, this->discovery_info_.retain);
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
void MQTTClientComponent::dump_config() { void MQTTClientComponent::dump_config() {

View File

@ -70,7 +70,7 @@ bool MQTTComponent::send_discovery_() {
ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name().c_str()); ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name().c_str());
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
return global_mqtt_client->publish_json( return global_mqtt_client->publish_json(
this->get_discovery_topic_(discovery_info), this->get_discovery_topic_(discovery_info),
[this](JsonObject root) { [this](JsonObject root) {
@ -81,7 +81,6 @@ bool MQTTComponent::send_discovery_() {
this->send_discovery(root, config); this->send_discovery(root, config);
// Set subscription QoS (default is 0) // Set subscription QoS (default is 0)
if (this->subscribe_qos_ != 0) { if (this->subscribe_qos_ != 0) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_QOS] = this->subscribe_qos_; root[MQTT_QOS] = this->subscribe_qos_;
} }
@ -190,11 +189,11 @@ bool MQTTComponent::send_discovery_() {
device_info[MQTT_DEVICE_SUGGESTED_AREA] = node_area; device_info[MQTT_DEVICE_SUGGESTED_AREA] = node_area;
} }
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
device_info[MQTT_DEVICE_CONNECTIONS][0][0] = "mac"; device_info[MQTT_DEVICE_CONNECTIONS][0][0] = "mac";
device_info[MQTT_DEVICE_CONNECTIONS][0][1] = mac; device_info[MQTT_DEVICE_CONNECTIONS][0][1] = mac;
}, },
this->qos_, discovery_info.retain); this->qos_, discovery_info.retain);
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
uint8_t MQTTComponent::get_qos() const { return this->qos_; } uint8_t MQTTComponent::get_qos() const { return this->qos_; }

View File

@ -1322,9 +1322,8 @@ std::string WebServer::climate_all_json_generator(WebServer *web_server, void *s
return web_server->climate_json((climate::Climate *) (source), DETAIL_ALL); return web_server->climate_json((climate::Climate *) (source), DETAIL_ALL);
} }
std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_config) { std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
return json::build_json([this, obj, start_config](JsonObject root) { return json::build_json([this, obj, start_config](JsonObject root) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
set_json_id(root, obj, "climate-" + obj->get_object_id(), start_config); set_json_id(root, obj, "climate-" + obj->get_object_id(), start_config);
const auto traits = obj->get_traits(); const auto traits = obj->get_traits();
int8_t target_accuracy = traits.get_target_temperature_accuracy_decimals(); int8_t target_accuracy = traits.get_target_temperature_accuracy_decimals();
@ -1332,37 +1331,31 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
char buf[16]; char buf[16];
if (start_config == DETAIL_ALL) { if (start_config == DETAIL_ALL) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonArray opt = root["modes"].to<JsonArray>(); JsonArray opt = root["modes"].to<JsonArray>();
for (climate::ClimateMode m : traits.get_supported_modes()) for (climate::ClimateMode m : traits.get_supported_modes())
opt.add(PSTR_LOCAL(climate::climate_mode_to_string(m))); opt.add(PSTR_LOCAL(climate::climate_mode_to_string(m)));
if (!traits.get_supported_custom_fan_modes().empty()) { if (!traits.get_supported_custom_fan_modes().empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonArray opt = root["fan_modes"].to<JsonArray>(); JsonArray opt = root["fan_modes"].to<JsonArray>();
for (climate::ClimateFanMode m : traits.get_supported_fan_modes()) for (climate::ClimateFanMode m : traits.get_supported_fan_modes())
opt.add(PSTR_LOCAL(climate::climate_fan_mode_to_string(m))); opt.add(PSTR_LOCAL(climate::climate_fan_mode_to_string(m)));
} }
if (!traits.get_supported_custom_fan_modes().empty()) { if (!traits.get_supported_custom_fan_modes().empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonArray opt = root["custom_fan_modes"].to<JsonArray>(); JsonArray opt = root["custom_fan_modes"].to<JsonArray>();
for (auto const &custom_fan_mode : traits.get_supported_custom_fan_modes()) for (auto const &custom_fan_mode : traits.get_supported_custom_fan_modes())
opt.add(custom_fan_mode); opt.add(custom_fan_mode);
} }
if (traits.get_supports_swing_modes()) { if (traits.get_supports_swing_modes()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonArray opt = root["swing_modes"].to<JsonArray>(); JsonArray opt = root["swing_modes"].to<JsonArray>();
for (auto swing_mode : traits.get_supported_swing_modes()) for (auto swing_mode : traits.get_supported_swing_modes())
opt.add(PSTR_LOCAL(climate::climate_swing_mode_to_string(swing_mode))); opt.add(PSTR_LOCAL(climate::climate_swing_mode_to_string(swing_mode)));
} }
if (traits.get_supports_presets() && obj->preset.has_value()) { if (traits.get_supports_presets() && obj->preset.has_value()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonArray opt = root["presets"].to<JsonArray>(); JsonArray opt = root["presets"].to<JsonArray>();
for (climate::ClimatePreset m : traits.get_supported_presets()) for (climate::ClimatePreset m : traits.get_supported_presets())
opt.add(PSTR_LOCAL(climate::climate_preset_to_string(m))); opt.add(PSTR_LOCAL(climate::climate_preset_to_string(m)));
} }
if (!traits.get_supported_custom_presets().empty() && obj->custom_preset.has_value()) { if (!traits.get_supported_custom_presets().empty() && obj->custom_preset.has_value()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
JsonArray opt = root["custom_presets"].to<JsonArray>(); JsonArray opt = root["custom_presets"].to<JsonArray>();
for (auto const &custom_preset : traits.get_supported_custom_presets()) for (auto const &custom_preset : traits.get_supported_custom_presets())
opt.add(custom_preset); opt.add(custom_preset);
@ -1415,6 +1408,7 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
root["state"] = root["target_temperature"]; root["state"] = root["target_temperature"];
} }
}); });
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
#endif #endif
@ -1690,9 +1684,8 @@ std::string WebServer::update_all_json_generator(WebServer *web_server, void *so
return web_server->update_json((update::UpdateEntity *) (source), DETAIL_STATE); return web_server->update_json((update::UpdateEntity *) (source), DETAIL_STATE);
} }
std::string WebServer::update_json(update::UpdateEntity *obj, JsonDetail start_config) { std::string WebServer::update_json(update::UpdateEntity *obj, JsonDetail start_config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
return json::build_json([this, obj, start_config](JsonObject root) { return json::build_json([this, obj, start_config](JsonObject root) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
set_json_id(root, obj, "update-" + obj->get_object_id(), start_config); set_json_id(root, obj, "update-" + obj->get_object_id(), start_config);
root["value"] = obj->update_info.latest_version; root["value"] = obj->update_info.latest_version;
switch (obj->state) { switch (obj->state) {
@ -1717,6 +1710,7 @@ std::string WebServer::update_json(update::UpdateEntity *obj, JsonDetail start_c
this->add_sorting_info_(root, obj); this->add_sorting_info_(root, obj);
} }
}); });
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
} }
#endif #endif