[multiple] Fix undefined behavior across components (#14639)
Some checks failed
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.14) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.14) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.14) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
Stale / stale (push) Has been cancelled
Lock closed issues and PRs / lock (push) Has been cancelled

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-09 07:33:08 -04:00
committed by GitHub
parent 0db9137d91
commit 31f4b4d00d
7 changed files with 26 additions and 28 deletions

View File

@@ -1,3 +1,4 @@
#include <cstddef>
#include <cstring>
#include "e131.h"
#ifdef USE_NETWORK
@@ -57,7 +58,7 @@ union E131RawPacket {
// We need to have at least one `1` value
// Get the offset of `property_values[1]`
const size_t E131_MIN_PACKET_SIZE = reinterpret_cast<size_t>(&((E131RawPacket *) nullptr)->property_values[1]);
const size_t E131_MIN_PACKET_SIZE = offsetof(E131RawPacket, property_values) + sizeof(uint8_t);
bool E131Component::join_igmp_groups_() {
if (this->listen_method_ != E131_MULTICAST)

View File

@@ -84,7 +84,7 @@ template<typename T, uint8_t SZ> class RestoringGlobalStringComponent : public P
this->rtc_ = global_preferences->make_preference<uint8_t[SZ]>(1944399030U ^ this->name_hash_);
bool hasdata = this->rtc_.load(&temp);
if (hasdata) {
this->value_.assign(temp + 1, temp[0]);
this->value_.assign(temp + 1, static_cast<uint8_t>(temp[0]));
}
this->last_checked_value_.assign(this->value_);
}

View File

@@ -139,7 +139,8 @@ void GroveMotorDriveTB6612FNG::stepper_run(StepperModeTypeT mode, int16_t steps,
}
void GroveMotorDriveTB6612FNG::stepper_stop() {
if (this->write_register(GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_STOP, nullptr, 1) != i2c::ERROR_OK) {
uint8_t status = 0;
if (this->write_register(GROVE_MOTOR_DRIVER_I2C_CMD_STEPPER_STOP, &status, 1) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Send stop stepper failed!");
this->status_set_warning();
return;

View File

@@ -28,12 +28,14 @@ class UARTStream : public Stream {
int available() override { return this->uart_->available(); }
int read() override {
uint8_t data;
this->uart_->read_byte(&data);
if (!this->uart_->read_byte(&data))
return -1;
return data;
}
int peek() override {
uint8_t data;
this->uart_->peek_byte(&data);
if (!this->uart_->peek_byte(&data))
return -1;
return data;
}
size_t write(uint8_t data) override {

View File

@@ -651,11 +651,7 @@ void Nextion::process_nextion_commands_() {
break;
}
int value = 0;
for (int i = 0; i < 4; ++i) {
value += to_process[i] << (8 * i);
}
int value = static_cast<int>(encode_uint32(to_process[3], to_process[2], to_process[1], to_process[0]));
NextionQueue *nb = this->nextion_queue_.front();
if (!nb || !nb->component) {
@@ -751,10 +747,8 @@ void Nextion::process_nextion_commands_() {
index = to_process.find('\0');
variable_name = to_process.substr(0, index);
// // Get variable name
int value = 0;
for (int i = 0; i < 4; ++i) {
value += to_process[i + index + 1] << (8 * i);
}
int value = static_cast<int>(
encode_uint32(to_process[index + 4], to_process[index + 3], to_process[index + 2], to_process[index + 1]));
ESP_LOGN(TAG, "Sensor: %s=%d", variable_name.c_str(), value);

View File

@@ -21,11 +21,11 @@ bool parse_ruuvi_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, RuuviP
const float temperature = temp_sign == 0 ? temp_val : -1 * temp_val;
const float humidity = data[0] * 0.5f;
const float pressure = (uint16_t(data[3] << 8) + uint16_t(data[4]) + 50000.0f) / 100.0f;
const float acceleration_x = (int16_t(data[5] << 8) + int16_t(data[6])) / 1000.0f;
const float acceleration_y = (int16_t(data[7] << 8) + int16_t(data[8])) / 1000.0f;
const float acceleration_z = (int16_t(data[9] << 8) + int16_t(data[10])) / 1000.0f;
const float battery_voltage = (uint16_t(data[11] << 8) + uint16_t(data[12])) / 1000.0f;
const float pressure = (encode_uint16(data[3], data[4]) + 50000.0f) / 100.0f;
const float acceleration_x = static_cast<int16_t>(encode_uint16(data[5], data[6])) / 1000.0f;
const float acceleration_y = static_cast<int16_t>(encode_uint16(data[7], data[8])) / 1000.0f;
const float acceleration_z = static_cast<int16_t>(encode_uint16(data[9], data[10])) / 1000.0f;
const float battery_voltage = encode_uint16(data[11], data[12]) / 1000.0f;
result.humidity = humidity;
result.temperature = temperature;
@@ -43,19 +43,19 @@ bool parse_ruuvi_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, RuuviP
if (adv_data.size() != 24)
return false;
const float temperature = (int16_t(data[0] << 8) + int16_t(data[1])) * 0.005f;
const float humidity = (uint16_t(data[2] << 8) | uint16_t(data[3])) / 400.0f;
const float pressure = ((uint16_t(data[4] << 8) | uint16_t(data[5])) + 50000.0f) / 100.0f;
const float acceleration_x = (int16_t(data[6] << 8) + int16_t(data[7])) / 1000.0f;
const float acceleration_y = (int16_t(data[8] << 8) + int16_t(data[9])) / 1000.0f;
const float acceleration_z = (int16_t(data[10] << 8) + int16_t(data[11])) / 1000.0f;
const float temperature = static_cast<int16_t>(encode_uint16(data[0], data[1])) * 0.005f;
const float humidity = encode_uint16(data[2], data[3]) / 400.0f;
const float pressure = (encode_uint16(data[4], data[5]) + 50000.0f) / 100.0f;
const float acceleration_x = static_cast<int16_t>(encode_uint16(data[6], data[7])) / 1000.0f;
const float acceleration_y = static_cast<int16_t>(encode_uint16(data[8], data[9])) / 1000.0f;
const float acceleration_z = static_cast<int16_t>(encode_uint16(data[10], data[11])) / 1000.0f;
const uint16_t power_info = (uint16_t(data[12] << 8) | data[13]);
const uint16_t power_info = encode_uint16(data[12], data[13]);
const float battery_voltage = ((power_info >> 5) + 1600.0f) / 1000.0f;
const float tx_power = ((power_info & 0x1F) * 2.0f) - 40.0f;
const float movement_counter = float(data[14]);
const float measurement_sequence_number = float(uint16_t(data[15] << 8) | uint16_t(data[16]));
const float measurement_sequence_number = float(encode_uint16(data[15], data[16]));
result.temperature = data[0] == 0x7F && data[1] == 0xFF ? NAN : temperature;
result.humidity = data[2] == 0xFF && data[3] == 0xFF ? NAN : humidity;

View File

@@ -99,7 +99,7 @@ struct MessageHeader {
// payload_size returns the amount of payload bytes to be read from the uart
// buffer after reading the header.
uint32_t payload_size() { return this->len - sizeof(this->type); }
uint32_t payload_size() { return this->len > sizeof(this->type) ? this->len - sizeof(this->type) : 0; }
} __attribute__((packed));
// StatusType denotes which 'page' of information needs to be retrieved.