Skip to content

fix(print): Fix format specifiers#12164

Merged
me-no-dev merged 2 commits intoespressif:masterfrom
lucasssvaz:fix/codeql_warn
Jan 12, 2026
Merged

fix(print): Fix format specifiers#12164
me-no-dev merged 2 commits intoespressif:masterfrom
lucasssvaz:fix/codeql_warn

Conversation

@lucasssvaz
Copy link
Member

Description of Change

This pull request standardizes the usage of format specifiers in Serial.printf calls across multiple example files, replacing %d and %u with %zu (for size_t values) and %lu (for unsigned long values). This improves type safety and ensures correct output formatting, especially on platforms where size_t and related types may differ in size from int or unsigned int.

Serial output formatting improvements:

  • Replaced %d and %u with %zu in Serial.printf statements for variables of type size_t in 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]
  • Updated %ld to %lu in Serial.printf for unsigned long variables, 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.

@lucasssvaz lucasssvaz self-assigned this Dec 22, 2025
@lucasssvaz lucasssvaz requested review from a team, SuGlider and me-no-dev as code owners December 22, 2025 16:33
@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Apply suggestions":
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 10 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 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 ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against d0c8651

@github-actions
Copy link
Contributor

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.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32C5000.000.00000.000.00
ESP32P4000.000.00000.000.00
ESP32S3000.000.00000.000.00
ESP32S2000.000.00000.000.00
ESP32C3💚 -320💚 -0.010.00000.000.00
ESP32C6000.000.00000.000.00
ESP32H2000.000.00000.000.00
ESP320⚠️ +320.00⚠️ +0.01000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32C5ESP32P4ESP32S3ESP32S2ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/AsyncUDP/examples/AsyncUDPClient--0000000000--00
libraries/AsyncUDP/examples/AsyncUDPMulticastServer--00000000----⚠️ +160
libraries/AsyncUDP/examples/AsyncUDPServer--00000000----00
libraries/BLE/examples/Beacon_Scanner--00----00--0000
libraries/ESP32/examples/ArduinoStackSize--00--0000--00⚠️ +320
libraries/ESP32/examples/RMT/RMTLoopback--00--0000--0000
libraries/ESP32/examples/Serial/OnReceiveError_BREAK_Demo--00--0000--00⚠️ +160
libraries/ESP32/examples/Serial/OnReceive_Demo--00--0000--00⚠️ +160
libraries/ESP32/examples/Serial/RxFIFOFull_Demo--00--0000--0000
libraries/ESP32/examples/Serial/RxTimeout_Demo--00--0000--0000
libraries/ESP32/examples/Serial/Serial_STD_Func_OnReceive--00--0000--0000
libraries/FFat/examples/FFat_Test--00--0000--0000
libraries/HTTPUpdateServer/examples/WebUpdater--00--0000----00
libraries/LittleFS/examples/LITTLEFS_test--00--0000--0000
libraries/SD/examples/SD_Test--00--00💚 -320--0000
libraries/SPIFFS/examples/SPIFFS_Test--00--0000--00⚠️ +160
libraries/Update/examples/HTTP_Client_AES_OTA_Update--00--0000----⚠️ +160
libraries/Update/examples/HTTP_Server_AES_OTA_Update--00--0000----00
libraries/Update/examples/OTAWebUpdater--00--0000----00
libraries/Update/examples/Signed_OTA_Update--00--0000----00
libraries/WebServer/examples/WebUpdate--00--0000----00
libraries/SD_MMC/examples/SDMMC_Test--00----------00
libraries/BluetoothSerial/examples/DiscoverConnect--------------00
libraries/ESP32/examples/DeepSleep/SmoothBlink_ULP_Code--------------00

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Test Results

 90 files   90 suites   33m 9s ⏱️
 66 tests  66 ✅ 0 💤 0 ❌
675 runs  675 ✅ 0 💤 0 ❌

Results for commit d0c8651.

♻️ This comment has been updated with latest results.

SuGlider

This comment was marked as resolved.

@SuGlider SuGlider self-requested a review December 31, 2025 18:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/%u to %zu for size_t variables (buffer sizes, data lengths, counts)
  • Updated format specifiers from %ld to %lu for unsigned long variables (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.

@lucasssvaz lucasssvaz added the Status: Pending Merge Pull Request is ready to be merged label Jan 8, 2026
@me-no-dev me-no-dev merged commit 1cf0fe3 into espressif:master Jan 12, 2026
94 checks passed
@lucasssvaz lucasssvaz deleted the fix/codeql_warn branch January 17, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Pending Merge Pull Request is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants