mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-21 21:43:26 +02:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user