fix(print): Fix format specifiers#12164
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 ...
|
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]
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Test Results 90 files 90 suites 33m 9s ⏱️ Results for commit d0c8651. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Pull request overview
This pull request standardizes format specifiers in Serial.printf calls across multiple example files to improve type safety. The changes replace incorrect format specifiers (%d, %u, %ld) with the appropriate ones (%zu for size_t, %lu for unsigned long) to ensure correct output formatting and prevent potential undefined behavior across different platforms.
Key changes:
- Updated format specifiers from
%d/%uto%zuforsize_tvariables (buffer sizes, data lengths, counts) - Updated format specifiers from
%ldto%luforunsigned longvariables (delay times, timestamps)
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/WebServer/examples/WebUpdate/WebUpdate.ino | Changed format specifier for upload.totalSize from %u to %zu |
| libraries/Update/examples/Signed_OTA_Update/Signed_OTA_Update.ino | Changed format specifiers for firmwareSize, signatureSize, and written from %d to %zu |
| libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.ino | Changed format specifiers for fsize and upload.totalSize from %d/%u to %zu |
| libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino | Changed format specifiers for progress percentage and upload.totalSize from %d/%u to %zu |
| libraries/Update/examples/HTTP_Client_AES_OTA_Update/HTTP_Client_AES_OTA_Update.ino | Changed format specifier for progress percentage from %d to %zu |
| libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino | Changed format specifier for flen from %u to %zu |
| libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | Changed format specifier for flen from %u to %zu |
| libraries/SD/examples/SD_Test/SD_Test.ino | Changed format specifier for flen from %u to %zu |
| libraries/LittleFS/examples/LITTLEFS_test/LITTLEFS_test.ino | Changed format specifier for flen from %u to %zu |
| libraries/HTTPUpdateServer/src/HTTPUpdateServer.h | Changed format specifier for upload.totalSize from %u to %zu |
| libraries/FFat/examples/FFat_Test/FFat_Test.ino | Changed format specifiers for flen, totalBytes(), and freeBytes() from %u to %zu |
| libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive/Serial_STD_Func_OnReceive.ino | Changed format specifier for len from %d to %zu |
| libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino | Changed format specifier for sentBytes from %d to %zu |
| libraries/ESP32/examples/Serial/RxFIFOFull_Demo/RxFIFOFull_Demo.ino | Changed format specifier for sentBytes from %d to %zu |
| libraries/ESP32/examples/Serial/OnReceive_Demo/OnReceive_Demo.ino | Changed format specifiers for available, sent_bytes, and received_bytes from %d to %zu |
| libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo/OnReceiveError_BREAK_Demo.ino | Changed format specifiers for available, sent_bytes, and received_bytes from %d to %zu |
| libraries/ESP32/examples/RMT/RMTLoopback/RMTLoopback.ino | Changed format specifier for rx_num_symbols from %d to %zu |
| libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code/SmoothBlink_ULP_Code.ino | Changed format specifier for fadeCycleDelay from %ld to %lu |
| libraries/ESP32/examples/ArduinoStackSize/ArduinoStackSize.ino | Changed format specifiers for getArduinoLoopTaskStackSize() and uxTaskGetStackHighWaterMark() from %d to %zu |
| libraries/BluetoothSerial/examples/DiscoverConnect/DiscoverConnect.ino | Changed format specifier for channels.size() from %d to %zu |
| libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino | Changed format specifiers for dataLength from %d to %zu |
| libraries/AsyncUDP/examples/AsyncUDPServer/AsyncUDPServer.ino | Changed format specifier for packet.length() from %u to %zu |
| libraries/AsyncUDP/examples/AsyncUDPMulticastServer/AsyncUDPMulticastServer.ino | Changed format specifier for packet.length() from %u to %zu |
| libraries/AsyncUDP/examples/AsyncUDPClient/AsyncUDPClient.ino | Changed format specifier for packet.length() from %u to %zu |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description of Change
This pull request standardizes the usage of format specifiers in
Serial.printfcalls across multiple example files, replacing%dand%uwith%zu(forsize_tvalues) and%lu(forunsigned longvalues). This improves type safety and ensures correct output formatting, especially on platforms wheresize_tand related types may differ in size fromintorunsigned int.Serial output formatting improvements:
%dand%uwith%zuinSerial.printfstatements for variables of typesize_tin UDP, Bluetooth, BLE, and Serial examples, ensuring proper formatting for buffer sizes, data lengths, and counts. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23]%ldto%luinSerial.printfforunsigned longvariables, such as delay times, to match the variable type in deep sleep and progress reporting examples. [1] [2]These changes help prevent formatting errors and potential undefined behavior, making the code more robust and portable across platforms.