mirror of
https://github.com/esphome/esphome.git
synced 2025-09-29 08:32:26 +01: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:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user