Skip to content

Fix all compiler warnings in the ESP-IDF build#111

Merged
eman merged 1 commit into
mainfrom
fix-compiler-warnings
Jul 20, 2026
Merged

Fix all compiler warnings in the ESP-IDF build#111
eman merged 1 commit into
mainfrom
fix-compiler-warnings

Conversation

@eman

@eman eman commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

The component emitted 21 compiler warnings in the ESP-IDF build; this brings it to zero. All 21 were format-string mismatches — no logic changes.

-Wformat= (19)

On ESP32, uint32_t is long unsigned int, so %u/%d didn't match the arguments being logged: millisecond timers, event/schedule timestamps, start counts, the service-discovery retry delay, and the BLE passkey. These now use PRIu32 from <cinttypes>.

ESPTime::timestamp is printed via a long long cast rather than a fixed specifier — time_t is long long on ESP-IDF but long on many hosts, and these sources are also compiled on the host by the test suite, so one cast keeps a single format string correct on both.

-Wformat-truncation= (2)

The get_begin_time() / get_end_time() helpers in schedule_entry.h format "HH:MM" into a char[6]. The compiler can't prove a uint8_t hour/minute renders in two digits, so it flagged possible truncation. Both fields are now bounded to two digits, which silences the warning and also keeps output well-formed if the pump ever reports an out-of-range byte.

Files touched

alpha_hwr.cpp, ble_connection_manager.cpp, device_info_service.cpp, event_log_service.cpp, schedule_entry.h, schedule_service.cpp, time_service.cpp, transport.cpp

Testing

  • Full ESP-IDF build (ESPHome 2026.7.0, esp32-c3): 0 warnings, down from 21. Verified every previously-warning translation unit was actually recompiled, not served from cache.
  • Host suite (cd tests && make clean && make test, built with -Wall -Wextra): 0 warnings, 494 assertions passing, 0 failures.
  • Not yet flashed to hardware. Per AGENTS.md §4 that's the normal gate, but this change only alters format specifiers and the values handed to them, so runtime behaviour is unchanged apart from log lines now rendering correctly instead of relying on ESP32 ABI luck.

The component emitted 21 warnings, all format mismatches.

-Wformat= (19): on ESP32 uint32_t is `long unsigned int`, so %u/%d did
not match the millisecond timers, timestamps, start counts, retry delay
and BLE passkey being logged. Switched to PRIu32 from <cinttypes>.
ESPTime::timestamp is now printed via a `long long` cast, since time_t
is `long long` on ESP-IDF but `long` on many hosts and the sources are
also compiled on the host by the test suite.

-Wformat-truncation= (2): the "HH:MM" helpers in schedule_entry.h write
into char[6], and the compiler cannot prove a uint8_t hour/minute
renders in two digits. Bounded both fields so the buffer can never
truncate, which also keeps the output well-formed if the pump ever
reports an out-of-range byte.

No behavioural change: only format specifiers and the values passed to
them changed.

Tested:
- Full ESP-IDF build (ESPHome 2026.7.0, esp32-c3): 0 warnings, was 21.
  All previously-warning translation units confirmed recompiled.
- Host suite `cd tests && make clean && make test` (-Wall -Wextra):
  0 warnings, 494 assertions passing, 0 failures.
@eman
eman merged commit fbea52b into main Jul 20, 2026
2 checks passed
@eman
eman deleted the fix-compiler-warnings branch July 20, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant