Fix all compiler warnings in the ESP-IDF build#111
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_tislong unsigned int, so%u/%ddidn't match the arguments being logged: millisecond timers, event/schedule timestamps, start counts, the service-discovery retry delay, and the BLE passkey. These now usePRIu32from<cinttypes>.ESPTime::timestampis printed via along longcast rather than a fixed specifier —time_tislong longon ESP-IDF butlongon 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 inschedule_entry.hformat"HH:MM"into achar[6]. The compiler can't prove auint8_thour/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.cppTesting
cd tests && make clean && make test, built with-Wall -Wextra): 0 warnings, 494 assertions passing, 0 failures.