mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 16:04:55 +00:00
[multiple] Fix assorted medium-severity bugs (#14555)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -263,7 +263,7 @@ class ByteBuffer {
|
||||
|
||||
void put_uint8(uint8_t value, size_t offset) { this->data_[offset] = value; }
|
||||
void put_uint16(uint16_t value, size_t offset) { this->put(value, offset); }
|
||||
void put_uint24(uint32_t value, size_t offset) { this->put(value, offset); }
|
||||
void put_uint24(uint32_t value, size_t offset) { this->put_uint32_(value, offset, 3); }
|
||||
void put_uint32(uint32_t value, size_t offset) { this->put(value, offset); }
|
||||
void put_uint64(uint64_t value, size_t offset) { this->put(value, offset); }
|
||||
// Signed versions of the put functions
|
||||
|
||||
@@ -92,7 +92,7 @@ void CAP1188Component::loop() {
|
||||
this->read_register(CAP1188_MAIN, &data, 1);
|
||||
data = data & ~CAP1188_MAIN_INT;
|
||||
|
||||
this->write_register(CAP1188_MAIN, &data, 2);
|
||||
this->write_register(CAP1188_MAIN, &data, 1);
|
||||
}
|
||||
|
||||
for (auto *channel : this->channels_) {
|
||||
|
||||
@@ -49,7 +49,7 @@ void HTE501Component::update() {
|
||||
this->set_timeout(50, [this]() {
|
||||
uint8_t i2c_response[6];
|
||||
this->read(i2c_response, 6);
|
||||
if (i2c_response[2] != crc8(i2c_response, 2, 0xFF, 0x31, true) &&
|
||||
if (i2c_response[2] != crc8(i2c_response, 2, 0xFF, 0x31, true) ||
|
||||
i2c_response[5] != crc8(i2c_response + 3, 2, 0xFF, 0x31, true)) {
|
||||
this->error_code_ = CRC_CHECK_FAILED;
|
||||
this->status_set_warning();
|
||||
|
||||
@@ -599,11 +599,7 @@ bool INA2XX::read_unsigned_16_(uint8_t reg, uint16_t &out) {
|
||||
}
|
||||
|
||||
int64_t INA2XX::two_complement_(uint64_t value, uint8_t bits) {
|
||||
if (value > (1ULL << (bits - 1))) {
|
||||
return (int64_t) (value - (1ULL << bits));
|
||||
} else {
|
||||
return (int64_t) value;
|
||||
}
|
||||
return (int64_t) (value << (64 - bits)) >> (64 - bits);
|
||||
}
|
||||
} // namespace ina2xx_base
|
||||
} // namespace esphome
|
||||
|
||||
@@ -407,7 +407,7 @@ void Inkplate::display1b_() {
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t clock = (1 << this->cl_pin_->get_pin());
|
||||
uint32_t clock = (1UL << this->cl_pin_->get_pin());
|
||||
uint32_t data_mask = this->get_data_pin_mask_();
|
||||
ESP_LOGV(TAG, "Display1b start loops (%ums)", millis() - start_time);
|
||||
|
||||
@@ -575,7 +575,7 @@ void Inkplate::display3b_() {
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t clock = (1 << this->cl_pin_->get_pin());
|
||||
uint32_t clock = (1UL << this->cl_pin_->get_pin());
|
||||
uint32_t data_mask = this->get_data_pin_mask_();
|
||||
uint32_t pos;
|
||||
uint32_t data;
|
||||
@@ -646,7 +646,7 @@ bool Inkplate::partial_update_() {
|
||||
int rep = (this->model_ == INKPLATE_6_V2) ? 6 : 5;
|
||||
|
||||
eink_on_();
|
||||
uint32_t clock = (1 << this->cl_pin_->get_pin());
|
||||
uint32_t clock = (1UL << this->cl_pin_->get_pin());
|
||||
uint32_t data_mask = this->get_data_pin_mask_();
|
||||
for (int k = 0; k < rep; k++) {
|
||||
vscan_start_();
|
||||
@@ -704,7 +704,7 @@ void Inkplate::vscan_start_() {
|
||||
}
|
||||
|
||||
void Inkplate::hscan_start_(uint32_t d) {
|
||||
uint8_t clock = (1 << this->cl_pin_->get_pin());
|
||||
uint32_t clock = (1UL << this->cl_pin_->get_pin());
|
||||
this->sph_pin_->digital_write(false);
|
||||
GPIO.out_w1ts = d | clock;
|
||||
GPIO.out_w1tc = this->get_data_pin_mask_() | clock;
|
||||
@@ -751,7 +751,7 @@ void Inkplate::clean_fast_(uint8_t c, uint8_t rep) {
|
||||
|
||||
uint32_t send = ((data & 0b00000011) << 4) | (((data & 0b00001100) >> 2) << 18) | (((data & 0b00010000) >> 4) << 23) |
|
||||
(((data & 0b11100000) >> 5) << 25);
|
||||
uint32_t clock = (1 << this->cl_pin_->get_pin());
|
||||
uint32_t clock = (1UL << this->cl_pin_->get_pin());
|
||||
|
||||
for (int k = 0; k < rep; k++) {
|
||||
vscan_start_();
|
||||
|
||||
@@ -364,11 +364,7 @@ void MSA3xxComponent::setup_offset_(float offset_x, float offset_y, float offset
|
||||
}
|
||||
|
||||
int64_t MSA3xxComponent::twos_complement_(uint64_t value, uint8_t bits) {
|
||||
if (value > (1ULL << (bits - 1))) {
|
||||
return (int64_t) (value - (1ULL << bits));
|
||||
} else {
|
||||
return (int64_t) value;
|
||||
}
|
||||
return (int64_t) (value << (64 - bits)) >> (64 - bits);
|
||||
}
|
||||
|
||||
void binary_event_debounce(bool state, bool old_state, uint32_t now, uint32_t &last_ms, Trigger<> &trigger,
|
||||
|
||||
@@ -14,6 +14,11 @@ NdefRecordText::NdefRecordText(const std::vector<uint8_t> &payload) {
|
||||
|
||||
uint8_t language_code_length = payload[0] & 0b00111111; // Todo, make use of encoding bit?
|
||||
|
||||
if (1 + language_code_length > payload.size()) {
|
||||
ESP_LOGE(TAG, "Record payload too short for language code");
|
||||
return;
|
||||
}
|
||||
|
||||
this->language_code_ = std::string(payload.begin() + 1, payload.begin() + 1 + language_code_length);
|
||||
|
||||
this->text_ = std::string(payload.begin() + 1 + language_code_length, payload.end());
|
||||
|
||||
@@ -35,7 +35,7 @@ uint8_t guess_tag_type(uint8_t uid_length) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data) {
|
||||
int8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data) {
|
||||
for (uint8_t i = 0; i < MIFARE_CLASSIC_BLOCK_SIZE; i++) {
|
||||
if (data[i] == 0x00) {
|
||||
// Do nothing, skip
|
||||
@@ -49,17 +49,25 @@ uint8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data) {
|
||||
}
|
||||
|
||||
bool decode_mifare_classic_tlv(std::vector<uint8_t> &data, uint32_t &message_length, uint8_t &message_start_index) {
|
||||
if (data.size() < MIFARE_CLASSIC_BLOCK_SIZE) {
|
||||
ESP_LOGE(TAG, "Error, data too short for NDEF detection.");
|
||||
return false;
|
||||
}
|
||||
auto i = get_mifare_classic_ndef_start_index(data);
|
||||
if (data[i] != 0x03) {
|
||||
if (i < 0 || data[i] != 0x03) {
|
||||
ESP_LOGE(TAG, "Error, Can't decode message length.");
|
||||
return false;
|
||||
}
|
||||
if (data[i + 1] == 0xFF) {
|
||||
message_length = ((0xFF & data[i + 2]) << 8) | (0xFF & data[i + 3]);
|
||||
message_start_index = i + MIFARE_CLASSIC_LONG_TLV_SIZE;
|
||||
uint8_t idx = static_cast<uint8_t>(i);
|
||||
if (idx + 4 <= data.size() && data[idx + 1] == 0xFF) {
|
||||
message_length = ((0xFF & data[idx + 2]) << 8) | (0xFF & data[idx + 3]);
|
||||
message_start_index = idx + MIFARE_CLASSIC_LONG_TLV_SIZE;
|
||||
} else if (idx + 2 <= data.size()) {
|
||||
message_length = data[idx + 1];
|
||||
message_start_index = idx + MIFARE_CLASSIC_SHORT_TLV_SIZE;
|
||||
} else {
|
||||
message_length = data[i + 1];
|
||||
message_start_index = i + MIFARE_CLASSIC_SHORT_TLV_SIZE;
|
||||
ESP_LOGE(TAG, "Error, TLV data too short.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ ESPDEPRECATED("Use format_bytes_to() with stack buffer instead. Removed in 2026.
|
||||
std::string format_bytes(std::span<const uint8_t> bytes);
|
||||
|
||||
uint8_t guess_tag_type(uint8_t uid_length);
|
||||
uint8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data);
|
||||
int8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data);
|
||||
bool decode_mifare_classic_tlv(std::vector<uint8_t> &data, uint32_t &message_length, uint8_t &message_start_index);
|
||||
uint32_t get_mifare_classic_buffer_size(uint32_t message_length);
|
||||
|
||||
|
||||
@@ -52,7 +52,11 @@ template<uint8_t SZ> class TextSaver : public TemplateTextSaverBase {
|
||||
bool hasdata = this->pref_.load(&temp);
|
||||
|
||||
if (hasdata) {
|
||||
value.assign(temp + 1, (size_t) temp[0]);
|
||||
size_t len = static_cast<uint8_t>(temp[0]);
|
||||
if (len > SZ) {
|
||||
len = SZ;
|
||||
}
|
||||
value.assign(temp + 1, len);
|
||||
}
|
||||
|
||||
this->prev_.assign(value);
|
||||
|
||||
Reference in New Issue
Block a user