fix(format): Fix and future-proof format specifiers#12404
Conversation
👋 Hello lucasssvaz, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
9e0928a to
8f3802a
Compare
There was a problem hiding this comment.
Pull request overview
This pull request standardizes format specifiers across the ESP32 Arduino core to improve type safety and future-proof the codebase against compiler changes. The changes replace platform-specific format specifiers (like %d, %u, %x, %lu) with portable C99 macros (PRIu32, PRIx8, %zu, etc.) and upgrade unsafe sprintf calls to snprintf to prevent buffer overflows. Additionally, the PR adds compile_commands.json as a CI artifact for debugging purposes.
Changes:
- Replaced format specifiers with C99 standard macros (PRIu32, PRIx8, PRIu16, etc.) throughout the codebase
- Upgraded sprintf to snprintf in multiple files to prevent buffer overflows
- Added compile_commands.json generation and merging as CI artifacts
Reviewed changes
Copilot reviewed 274 out of 274 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| variants/sensebox_/.ino | Updated format specifiers in OTA examples |
| tests/**/*.ino | Standardized format specifiers in validation and performance tests |
| libraries/Zigbee/src/**/*.cpp | Fixed format specifiers in Zigbee library |
| libraries/WiFi/src/*.cpp | Replaced sprintf with snprintf, updated format specifiers |
| libraries/Wire/src/*.cpp | Updated format specifiers for I2C operations |
| libraries/USB/src/*.cpp | Fixed format specifiers in USB library |
| libraries/Matter/src/**/*.cpp | Standardized format specifiers in Matter library |
| libraries/BLE/src/*.cpp | Added inttypes.h includes and updated format specifiers |
| cores/esp32/.c/.cpp | Core library format specifier updates and sprintf→snprintf |
| .github/workflows/push.yml | Added compile commands artifact generation |
| .github/scripts/sketch_utils.sh | Added compile commands collection logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test Results 94 files 94 suites 26m 34s ⏱️ Results for commit a1cf0a1. ♻️ This comment has been updated with latest results. |
8f3802a to
7204a37
Compare
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bd74291 to
73545cd
Compare
73545cd to
7b977d5
Compare
|
@lucasssvaz will do a framework build and test with the Tasmota build which failed because nano lib incompatibility in Arduino core. Feedback in a few hours |
Description of Change
This pull request introduces improvements to logging and string formatting for large integer values across the codebase, as well as enhancements to the CI workflow for compile command collection and merging. The main changes are grouped into two themes: workflow enhancements and codebase improvements for integer handling.
Workflow enhancements:
compile_commands.jsonartifacts during CI builds, including a new step to merge these files from all build chunks into a single artifact for easier consumption. (.github/workflows/push.yml,.github/scripts/sketch_utils.sh) [1] [2] [3] [4]Codebase improvements for integer handling and logging:
sprintfwithsnprintffor safer string formatting, and standardized logging format specifiers to correctly handle 64-bit and unsigned values, improving reliability and correctness in log output. (cores/esp32/FirmwareMSC.cpp,cores/esp32/HEXBuilder.cpp,cores/esp32/HardwareSerial.cpp,cores/esp32/HWCDC.cpp,cores/esp32/MacAddress.cpp) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19]StringUtils.cpputility for converting 64-bit integers to strings, including safe handling for negative values, and exposed conversion functions for use with theStringclass. (cores/esp32/StringUtils.cpp)Printclass to handle edge cases correctly, especially forINT64_MIN. (cores/esp32/Print.cpp)These changes improve build artifact management in CI and ensure robust handling and logging of large integer values throughout the codebase.
Test Scenarios
Tested locally