Commit Graph
260 Commits
Author SHA1 Message Date
J. Nick Koston db15bb2494 Merge remote-tracking branch 'upstream/callback-manager-no-vector' into integration 2026-03-28 08:27:47 -10:00
J. Nick Koston fa2b14ef41 Guard against nullptr+0 UB in call() and fix assert bound
- Add early return when size_==0 to avoid nullptr+0 pointer
  arithmetic (UB per C++ standard, even though all ESPHome
  targets treat it as no-op)
- Fix debug assert: size < UINT16_MAX allows capacity up to 65535
2026-03-27 16:47:56 -10:00
J. Nick Koston acef5ad5bb Fix off-by-one in debug assert: size + 1 must also fit in uint16_t 2026-03-27 15:59:01 -10:00
J. Nick Koston fe8e7c134c Add debug assert for uint16_t overflow in callback_manager_grow 2026-03-27 15:53:47 -10:00
J. Nick Koston 1bdf6402a2 Move grow path to helpers.cpp as non-template function
Since Callback is trivially copyable regardless of signature,
the grow logic is type-independent. Move it to a concrete
function in helpers.cpp using void*/memcpy, eliminating the
template definition from the header entirely.
2026-03-27 15:52:33 -10:00
J. Nick Koston 84727b1f71 [esp32] Validate eFuse MAC reads and reject garbage MACs (#15049) 2026-03-22 12:41:01 -10:00
J. Nick Koston 0761170514 Merge remote-tracking branch 'upstream/fix-esp32-efuse-mac-validation' into integration 2026-03-20 22:14:39 -10:00
J. Nick Koston 935ab42b1e [esp32] Validate eFuse MAC reads and reject garbage MACs
On some ESP32 boards (especially cheap clones), the eFuse custom MAC
area contains random garbage that passes the existing all-zeros/all-ones
validation. Additionally, esp_efuse_mac_get_default() can fail with CRC
errors, but the return value was being ignored, causing garbage MAC
addresses to be advertised via mDNS.

This caused Home Assistant to report false "MAC address changed" device
conflicts on every boot.

Two fixes:
- Check return values from eFuse MAC read functions and add a fallback
  chain: custom MAC -> default MAC -> raw eFuse bytes -> zeroed MAC.
- Reject multicast MACs (bit 0 of first byte set) in mac_address_is_valid()
  since device MACs must always be unicast.

Closes https://github.com/esphome/esphome/issues/14501
2026-03-20 22:13:01 -10:00
J. Nick Koston 95dea59382 [core] Use SplitMix32 PRNG for random_uint32() (#14984) 2026-03-20 15:25:54 -10:00
J. Nick Koston d53fb75b98 Merge remote-tracking branch 'origin/splitmix32-random' into integration 2026-03-19 14:45:46 -10:00
J. Nick Koston 8e6bc37785 Ensure non-zero seed after random_bytes() 2026-03-19 13:41:04 -10:00
J. Nick Koston bcc0180cd2 Merge remote-tracking branch 'upstream/splitmix32-random' into integration 2026-03-19 13:38:46 -10:00
J. Nick Koston e2a59daabc Add SplitMix32 references for reviewers 2026-03-19 13:37:26 -10:00
J. Nick Koston 2af50329f4 Document design trade-off for state==0 reseed 2026-03-19 13:36:08 -10:00
J. Nick Koston 1b090e6b95 Address review: use 'secure RNG' instead of 'hardware RNG' in comments 2026-03-19 13:35:43 -10:00
J. Nick Koston f02bf07630 [core] Use SplitMix32 PRNG for random_uint32() across platforms
Replace platform-specific random_uint32() implementations with a
unified SplitMix32 PRNG seeded from random_bytes(). This provides
consistent, fast, non-cryptographic random numbers on all platforms.

ESP8266 retains os_random() as it is already faster on that platform.

Benchmarked on real hardware (ns/call, before -> after):
- RP2040: 2815 -> 333 (8.5x faster)
- ESP32: 871 -> 354 (2.5x faster)
- BK72xx: 1073 -> 882 (1.2x faster, replaces weak rand())
- RTL87xx: 330 -> 283 (1.2x faster, replaces weak rand())
- ESP8266: 763 (unchanged, keeps os_random())

random_bytes() remains platform-specific hardware RNG for crypto use.
2026-03-19 13:17:24 -10:00
J. Nick Koston 78602ccacb [ci] Add lint check to prevent powf in core and base entity platforms (#14126) 2026-03-03 07:03:50 -10:00
J. Nick Koston db15b94cd7 [core] Inline HighFrequencyLoopRequester::is_high_frequency() (#14423) 2026-03-03 03:17:20 +00:00
J. Nick Koston 2c7ae6f52d Merge remote-tracking branch 'origin/inline-is-high-frequency' into integration 2026-03-02 16:53:05 -10:00
J. Nick Koston efc29773a3 [core] Inline HighFrequencyLoopRequester::is_high_frequency()
Move is_high_frequency() from out-of-line definition in helpers.cpp
to inline in the header. This allows the compiler to inline the
trivial check (num_requests > 0) at the call site in
Application::loop(), avoiding a function call every loop iteration.
2026-03-02 16:27:36 -10:00
J. Nick Koston b6ea52b6a7 Merge remote-tracking branch 'upstream/lint-no-powf-core' into integration 2026-03-02 16:02:44 -10:00
J. Nick Koston f255f03822 Merge remote-tracking branch 'upstream/dev' into lint-no-powf-core
# Conflicts:
#	esphome/core/helpers.h
#	script/ci-custom.py
2026-02-23 17:05:39 -06:00
J. Nick KostonandClaude Opus 4.6 869678953d [core] Add pow10_int helper, replace powf in normalize_accuracy and sensor filters (#14114)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 12:03:24 +13:00
J. Nick Koston 5de56714c0 Merge branch 'setup_heap_stats' into integration 2026-02-20 19:31:55 -06:00
J. Nick KostonandClaude Opus 4.6 35037d1a5b [core] Deduplicate base64 encode/decode logic (#14143)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 19:20:58 -06:00
J. Nick Koston 607fcb4254 Merge branch 'base64_decode_dedup' into integration
# Conflicts:
#	esphome/core/helpers.cpp
2026-02-20 00:15:32 -06:00
J. Nick KostonandClaude Opus 4.6 fbc2d6c066 [core] Also deduplicate base64_encode 3-to-4 byte conversion
Same pattern as the decode side - the bit manipulation was
duplicated in the main loop and tail path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:12:10 -06:00
J. Nick KostonandClaude Opus 4.6 f291773d5c [core] Remove unnecessary input contract comment
base64_find_char() safely handles any input including 0,
returning 0 via strchr fallback - no special contract needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:10:14 -06:00
J. Nick KostonandClaude Opus 4.6 cdc40101d4 [core] Document base64_decode_quad_ input requirements
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:08:58 -06:00
J. Nick KostonandClaude Opus 4.6 af4d4b35ae [core] Also deduplicate base64 output copy loop
Fold the output copy loop into base64_decode_quad_ since both
call sites use the same truncation-checked copy logic, differing
only in count (3 vs i-1).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:08:09 -06:00
J. Nick KostonandClaude Opus 4.6 4b53f6ef2b [core] Extract base64_decode_quad_ to deduplicate base64 decode logic
The base64 character-to-byte conversion and output copy loop were
duplicated in both the main decode loop and the tail/padding path.
Extract into a shared static helper to reduce flash usage (-64 bytes
on ESP32) and eliminate duplicated logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:07:20 -06:00
J. Nick KostonandClaude Opus 4.6 9a028f37ba [core] Extract base64_decode_quad_ to deduplicate base64 decode logic
The base64 character-to-byte conversion was duplicated in both the
main decode loop and the tail/padding path. Extract into a shared
static helper to reduce flash usage (-64 bytes on ESP32).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:02:27 -06:00
J. Nick Koston eb83c85a08 [ci] Add lint check to prevent powf in core and base entity platforms
Add a ci-custom.py check that prevents powf() from being introduced
into esphome/core/ and base entity platform components (sensor, light,
climate, etc.). These files are linked into every build, and powf
pulls in __ieee754_powf (~2.3KB flash).

Existing legitimate uses of powf with non-integer exponents (gamma
correction in helpers.cpp) are excluded. New uses can opt out with
// NOLINT if truly necessary.
2026-02-19 15:56:19 -06:00
J. Nick Koston e95879ba6f Merge remote-tracking branch 'origin/remove-powf-normalize-accuracy' into integration 2026-02-19 15:32:33 -06:00
J. Nick Koston 6a8844e2fc [sensor] Replace powf with pow10_int in sensor filters
Add shared pow10_int() helper to helpers.h that computes 10^exp
using iterative multiplication/division instead of powf.

Replace powf(10, exp) calls in:
- sensor/filter.cpp: ValueListFilter and RoundFilter
- helpers.cpp: normalize_accuracy_decimals (refactored to use
  pow10_int for the general case, keeping -1/-2 fast paths)

Eliminates powf/__ieee754_powf from builds where sensor filters
are the only remaining powf call site.
2026-02-19 15:28:12 -06:00
J. Nick Koston ffb75eed3d Merge branch 'remove-powf-normalize-accuracy' into integration 2026-02-19 15:09:02 -06:00
J. Nick Koston d2b7d40716 Clamp accuracy_decimals to -9 to prevent uint32_t overflow 2026-02-19 12:17:19 -06:00
J. Nick Koston 77ef231a3a Merge branch 'remove-powf-normalize-accuracy' into integration 2026-02-19 12:11:28 -06:00
J. Nick Koston 2bb077cb1f [core] Replace powf with integer math in normalize_accuracy_decimals
Replace powf(10.0f, accuracy_decimals) with integer divisor computation
to avoid pulling in __ieee754_powf (~2.2KB) on builds where this is
the only powf call site.

Tested on ESP8266 with web_server: -3.1KB flash, -16 bytes RAM.
2026-02-19 12:10:51 -06:00
J. Nick Koston dff9780d3a [core] Use constexpr for compile-time constants (#14071) 2026-02-19 03:19:48 +00:00
J. Nick Koston f9c171b347 Merge branch 'constexpr-core-constants' into integration 2026-02-18 20:55:39 -06:00
J. Nick Koston cf2e9dfd11 [core] Use constexpr for compile-time constants
Replace const with constexpr for integer constants initialized
with literal values to enable compile-time evaluation.
2026-02-18 20:31:00 -06:00
J. Nick Koston a7c28fb68a Merge branch 'compact_string_wifi' into integration 2026-02-11 14:53:45 -06:00
J. Nick Koston 2506831445 contain complexity into wifi 2026-02-11 13:34:18 -06:00
J. Nick Koston ce5b93d9ca Merge branch 'dev' into compact_string_wifi 2026-02-09 07:24:27 -06:00
J. Nick Koston c3622ef7fb [http_request] Fix chunked transfer encoding on Arduino platforms (#13790) 2026-02-06 15:52:41 +01:00
J. Nick Koston d6466bdbc7 Merge branch 'ard_chunked_http_request' into integration 2026-02-06 11:23:51 +01:00
J. Nick Koston 548b434f49 [http_request] Fix chunked transfer encoding on Arduino platforms 2026-02-06 11:22:52 +01:00
J. Nick Koston a3c2248b44 Merge upstream/dev into compact_string_wifi 2026-01-28 05:51:28 -10:00
J. Nick Koston 4ddd40bcfb [core] Add PROGMEM string comparison helpers and use in cover/valve/helpers (#13545) 2026-01-26 17:19:50 -10:00