Activate owning-memory clang-tidy check (#1891)

* Activate owning-memory clang-tidy check

* Lint

* Lint

* Fix issue with new NfcTag constructor

* Update pointers for number and select

* Add back the NOLINT to display buffer

* Fix merge

* DSMR fixes

* Nextion fixes

* Fix pipsolar

* Fix lwip socket

* Format

* Change socket fix

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Otto Winter
2021-09-13 11:31:02 +02:00
committed by GitHub
parent e0cff214b2
commit a4867a00ea
75 changed files with 293 additions and 321 deletions
+3 -2
View File
@@ -230,10 +230,11 @@ void GPIOPin::attach_interrupt_(void (*func)(void *), void *arg, int mode) const
}
}
#ifdef ARDUINO_ARCH_ESP8266
ArgStructure *as = new ArgStructure;
ArgStructure *as = new ArgStructure; // NOLINT
as->interruptInfo = nullptr;
as->functionInfo = new ESPHomeInterruptFuncInfo{
// NOLINT
.func = func,
.arg = arg,
};
@@ -249,7 +250,7 @@ void GPIOPin::attach_interrupt_(void (*func)(void *), void *arg, int mode) const
}
ISRInternalGPIOPin *GPIOPin::to_isr() const {
return new ISRInternalGPIOPin(this->pin_,
return new ISRInternalGPIOPin(this->pin_, // NOLINT
#ifdef ARDUINO_ARCH_ESP32
this->gpio_clear_, this->gpio_set_,
#endif
-15
View File
@@ -141,21 +141,6 @@ std::string uint32_to_string(uint32_t num) {
snprintf(buffer, sizeof(buffer), "%04X%04X", address16[1], address16[0]);
return std::string(buffer);
}
static char *global_json_build_buffer = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static size_t global_json_build_buffer_size = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void reserve_global_json_build_buffer(size_t required_size) {
if (global_json_build_buffer_size == 0 || global_json_build_buffer_size < required_size) {
delete[] global_json_build_buffer;
global_json_build_buffer_size = std::max(required_size, global_json_build_buffer_size * 2);
size_t remainder = global_json_build_buffer_size % 16U;
if (remainder != 0)
global_json_build_buffer_size += 16 - remainder;
global_json_build_buffer = new char[global_json_build_buffer_size];
}
}
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off) {
if (on == nullptr && strcasecmp(str, "on") == 0)
+1 -1
View File
@@ -338,7 +338,7 @@ template<typename T> T *new_buffer(size_t length) {
buffer = new T[length];
}
#else
buffer = new T[length];
buffer = new T[length]; // NOLINT
#endif
return buffer;
+5 -10
View File
@@ -17,13 +17,8 @@ namespace esphome {
static const char *const TAG = "preferences";
ESPPreferenceObject::ESPPreferenceObject() : offset_(0), length_words_(0), type_(0), data_(nullptr) {}
ESPPreferenceObject::ESPPreferenceObject(size_t offset, size_t length, uint32_t type)
: offset_(offset), length_words_(length), type_(type) {
this->data_ = new uint32_t[this->length_words_ + 1]; // NOLINT(cppcoreguidelines-prefer-member-initializer)
for (uint32_t i = 0; i < this->length_words_ + 1; i++)
this->data_[i] = 0;
}
: offset_(offset), length_words_(length), type_(type), data_(length + 1) {}
bool ESPPreferenceObject::load_() {
if (!this->is_initialized()) {
ESP_LOGV(TAG, "Load Pref Not initialized!");
@@ -173,7 +168,7 @@ ESPPreferences::ESPPreferences()
: current_offset_(0) {}
void ESPPreferences::begin() {
this->flash_storage_ = new uint32_t[ESP8266_FLASH_STORAGE_SIZE];
this->flash_storage_ = new uint32_t[ESP8266_FLASH_STORAGE_SIZE]; // NOLINT
ESP_LOGVV(TAG, "Loading preferences from flash...");
{
@@ -234,7 +229,7 @@ bool ESPPreferenceObject::save_internal_() {
char key[32];
sprintf(key, "%u", this->offset_);
uint32_t len = (this->length_words_ + 1) * 4;
esp_err_t err = nvs_set_blob(global_preferences.nvs_handle_, key, this->data_, len);
esp_err_t err = nvs_set_blob(global_preferences.nvs_handle_, key, this->data_.data(), len);
if (err) {
ESP_LOGV(TAG, "nvs_set_blob('%s', len=%u) failed: %s", key, len, esp_err_to_name(err));
return false;
@@ -264,7 +259,7 @@ bool ESPPreferenceObject::load_internal_() {
ESP_LOGVV(TAG, "NVS length does not match. Assuming key changed (%u!=%u)", actual_len, len);
return false;
}
err = nvs_get_blob(global_preferences.nvs_handle_, key, this->data_, &len);
err = nvs_get_blob(global_preferences.nvs_handle_, key, this->data_.data(), &len);
if (err) {
ESP_LOGV(TAG, "nvs_get_blob('%s') failed: %s", key, esp_err_to_name(err));
return false;
@@ -301,7 +296,7 @@ uint32_t ESPPreferenceObject::calculate_crc_() const {
}
return crc;
}
bool ESPPreferenceObject::is_initialized() const { return this->data_ != nullptr; }
bool ESPPreferenceObject::is_initialized() const { return !this->data_.empty(); }
ESPPreferences global_preferences; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
+13 -10
View File
@@ -1,6 +1,8 @@
#pragma once
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include "esphome/core/defines.h"
@@ -9,7 +11,7 @@ namespace esphome {
class ESPPreferenceObject {
public:
ESPPreferenceObject();
ESPPreferenceObject() = default;
ESPPreferenceObject(size_t offset, size_t length, uint32_t type);
template<typename T> bool save(T *src);
@@ -28,12 +30,12 @@ class ESPPreferenceObject {
uint32_t calculate_crc_() const;
size_t offset_;
size_t length_words_;
uint32_t type_;
uint32_t *data_;
size_t offset_ = 0;
size_t length_words_ = 0;
uint32_t type_ = 0;
std::vector<uint32_t> data_;
#ifdef ARDUINO_ARCH_ESP8266
bool in_flash_{false};
bool in_flash_ = false;
#endif
};
@@ -92,17 +94,18 @@ template<typename T> ESPPreferenceObject ESPPreferences::make_preference(uint32_
template<typename T> bool ESPPreferenceObject::save(T *src) {
if (!this->is_initialized())
return false;
memset(this->data_, 0, this->length_words_ * 4);
memcpy(this->data_, src, sizeof(T));
// ensure all bytes are 0 (in case sizeof(T) is not multiple of 4)
std::fill_n(data_.begin(), length_words_, 0);
memcpy(data_.data(), src, sizeof(T));
return this->save_();
}
template<typename T> bool ESPPreferenceObject::load(T *dest) {
memset(this->data_, 0, this->length_words_ * 4);
std::fill_n(data_.begin(), length_words_, 0);
if (!this->load_())
return false;
memcpy(dest, this->data_, sizeof(T));
memcpy(dest, data_.data(), sizeof(T));
return true;
}