diff --git a/.clang-tidy.hash b/.clang-tidy.hash index 122530625f..df86e098f1 100644 --- a/.clang-tidy.hash +++ b/.clang-tidy.hash @@ -1,5 +1,9 @@ <<<<<<< HEAD +<<<<<<< HEAD a172e2f65981e98354cc6b5ecf69bdb055dd13602226042ab2c7acd037a2bf41 ======= d565b0589e35e692b5f2fc0c14723a99595b4828a3a3ef96c442e86a23176c00 >>>>>>> mqtt_enum_flash +======= +a172e2f65981e98354cc6b5ecf69bdb055dd13602226042ab2c7acd037a2bf41 +>>>>>>> upstream/dev diff --git a/esphome/components/nfc/nfc_tag.h b/esphome/components/nfc/nfc_tag.h index 7b353468b0..0ded4cd6ee 100644 --- a/esphome/components/nfc/nfc_tag.h +++ b/esphome/components/nfc/nfc_tag.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "esphome/core/helpers.h" #include "esphome/core/log.h" @@ -16,20 +17,20 @@ using NfcTagUid = StaticVector; class NfcTag { public: NfcTag() { this->tag_type_ = "Unknown"; }; - NfcTag(NfcTagUid &uid) { + NfcTag(const NfcTagUid &uid) { this->uid_ = uid; this->tag_type_ = "Unknown"; }; - NfcTag(NfcTagUid &uid, const std::string &tag_type) { + NfcTag(const NfcTagUid &uid, const std::string &tag_type) { this->uid_ = uid; this->tag_type_ = tag_type; }; - NfcTag(NfcTagUid &uid, const std::string &tag_type, std::unique_ptr ndef_message) { + NfcTag(const NfcTagUid &uid, const std::string &tag_type, std::unique_ptr ndef_message) { this->uid_ = uid; this->tag_type_ = tag_type; this->ndef_message_ = std::move(ndef_message); }; - NfcTag(NfcTagUid &uid, const std::string &tag_type, std::vector &ndef_data) { + NfcTag(const NfcTagUid &uid, const std::string &tag_type, std::vector &ndef_data) { this->uid_ = uid; this->tag_type_ = tag_type; this->ndef_message_ = make_unique(ndef_data); diff --git a/esphome/components/pn532/pn532.cpp b/esphome/components/pn532/pn532.cpp index 0cda44e2cb..733810c242 100644 --- a/esphome/components/pn532/pn532.cpp +++ b/esphome/components/pn532/pn532.cpp @@ -168,11 +168,11 @@ void PN532::loop() { } uint8_t nfcid_length = read[5]; - nfc::NfcTagUid nfcid(read.begin() + 6, read.begin() + 6 + nfcid_length); - if (read.size() < 6U + nfcid_length) { + if (nfcid_length > nfc::NFC_UID_MAX_LENGTH || read.size() < 6U + nfcid_length) { // oops, pn532 returned invalid data return; } + nfc::NfcTagUid nfcid(read.begin() + 6, read.begin() + 6 + nfcid_length); bool report = true; for (auto *bin_sens : this->binary_sensors_) { @@ -448,7 +448,7 @@ void PN532::dump_config() { } } -bool PN532BinarySensor::process(nfc::NfcTagUid &data) { +bool PN532BinarySensor::process(const nfc::NfcTagUid &data) { if (data.size() != this->uid_.size()) return false; diff --git a/esphome/components/pn532/pn532.h b/esphome/components/pn532/pn532.h index e1894a90af..488ec4af3b 100644 --- a/esphome/components/pn532/pn532.h +++ b/esphome/components/pn532/pn532.h @@ -120,7 +120,7 @@ class PN532BinarySensor : public binary_sensor::BinarySensor { public: void set_uid(const nfc::NfcTagUid &uid) { uid_ = uid; } - bool process(nfc::NfcTagUid &data); + bool process(const nfc::NfcTagUid &data); void on_scan_end() { if (!this->found_) { diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 7493d95d20..541aaa0831 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -291,6 +291,10 @@ template class StaticVector { reverse_iterator rend() { return reverse_iterator(begin()); } const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } + + // Conversion to std::span for compatibility with span-based APIs + operator std::span() { return std::span(data_.data(), count_); } + operator std::span() const { return std::span(data_.data(), count_); } }; /// Fixed-capacity vector - allocates once at runtime, never reallocates