Repository navigation
feat(lint): ban raw C printf-family in src/ — use fl::snprintf (#2773 item 1.5) - #2777
Merged
Merged
Conversation
…item 1.5) Adds `CstdioPrintfChecker` to the unified `ci/lint_cpp/` pipeline that fails CI on direct C `snprintf` / `printf` / `sprintf` / `fprintf` / `vfprintf` / `vsnprintf` / `vprintf` / `vsprintf` / `vfiprintf` calls inside `src/`. Implements item **1.5** of the binary-size meta-issue (#2773) — the regression guard for the cleanup landed in #2774. Each such call drags newlib's `_svfprintf_r` (~11 KB on xtensa-esp-elf) into `libFastLED.a`. The repo already ships `fl::snprintf` and `fl::printf` at `src/fl/stl/stdio.h:659` which route through `fl::sstream` and don't need the libc engine. ## Allowed forms (verified by tests) - `fl::snprintf(...)`, `fl::printf(...)` — the FastLED wrappers. - `obj.printf(...)`, `ptr->printf(...)` — member access. - `SerialPort::printf(...)`, `MyClass::snprintf(...)` — any user-defined class method (qualified by an identifier other than `std`). - `void printf(const char* fmt, ...)` — function declarations / definitions inside a class body (the prefix ends with a type identifier, not `::`). - `my_snprintf(...)` — sub-word matches (defensive; `\b` already covers). ## Banned forms (verified by tests) - bare `snprintf(...)`, `printf(...)`, etc. — no prefix. - explicit `::printf(...)` — root-namespace C call. - explicit `std::snprintf(...)` — C++ std namespace (still newlib on xtensa). ## Excluded paths (don't link newlib) - `src/third_party/**` — third-party code defines its own conventions. - `src/fl/stl/stdio.{h,hpp}` + `src/fl/stl/cstdio.*` — wrapper TUs that bridge at the C-API boundary. - `src/platforms/wasm/**` — Emscripten libc, console-write. - `src/platforms/{posix,apple,win}/**` — host-only test runners. - `src/platforms/stub/**` — host-only stub. ## Opt-out Append `// ok cstdio - <reason>` on the same line for genuine platform-boundary cases. ## Verification - 26 unit tests covering every allowed/banned/opt-out/exclusion case (`ci/lint_cpp/test_cstdio_printf_checker.py`): 26/26 pass. - Full `bash lint` pipeline: clean, zero violations on `src/` after #2774 lands the snprintf → fl::snprintf migration. - Registered in `ci/lint_cpp/run_all_checkers.py` under the `src` scope alongside the existing `CtypeGlobalChecker` (same shape: ban C free-function APIs that have `fl::` template wrappers). Depends on #2774 — if rebased on master before that PR merges, the linter would fail on the 12 pre-existing `snprintf` call sites the PR migrates. Issue: #2773 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Adds
CstdioPrintfCheckerto the unifiedci/lint_cpp/pipeline thatfails CI on direct C
snprintf/printf/sprintf/fprintf/vfprintf/vsnprintf/vprintf/vsprintf/vfiprintfcallsinside
src/. Implements item 1.5 of the binary-size meta-issue:#2773 — the regression guard for the cleanup landed in #2774.
Each such call drags newlib's
_svfprintf_r(~11 KB on xtensa-esp-elf)into
libFastLED.a. The repo already shipsfl::snprintfandfl::printfatsrc/fl/stl/stdio.h:659which route throughfl::sstreamand don't need the libc engine.Allowed forms (covered by tests)
fl::snprintf(...),fl::printf(...)— the FastLED wrappers.obj.printf(...),ptr->printf(...)— member access.SerialPort::printf(...),MyClass::snprintf(...)— user-definedclass methods (qualified by an identifier other than
std).void printf(const char* fmt, ...)inside a class body — functiondeclarations / definitions (the prefix ends with a type, not
::).my_snprintf(...)— sub-word matches (defensive;\balready covers).Banned forms (covered by tests)
snprintf(...),printf(...),fprintf(...), etc.::printf(...)— root-namespace C call.std::snprintf(...)— C++ std namespace (still newlib).Excluded paths (don't link newlib)
src/third_party/**— third-party code defines its own conventions.src/fl/stl/stdio.{h,hpp}+src/fl/stl/cstdio.*— wrapper TUs thatbridge at the C-API boundary.
src/platforms/wasm/**— Emscripten libc, console-write.src/platforms/{posix,apple,win}/**— host-only test runners.src/platforms/stub/**— host-only stub.Opt-out
Append
// ok cstdio - <reason>on the same line for genuineplatform-boundary cases.
Test plan
ci/lint_cpp/test_cstdio_printf_checker.py): everyallowed/banned/opt-out/exclusion case → 26/26 pass.
refactor(printf): replace C snprintf with fl::snprintf in libFastLED.a (#2773 batch-1 item 1.1) #2774's migration.
bash lintpipeline: clean.ci/lint_cpp/run_all_checkers.pyunder thesrcscope alongside the existing
CtypeGlobalChecker(same shape: banC free-function APIs that have
fl::template wrappers).Files
ci/lint_cpp/cstdio_printf_checker.py— the checker, ~190 linesincluding module-level docstring with rationale and `ESP32-S3 binary size: 657 KB on master vs 344 KB on 3.10.3 — remaining +313 KB delta breakdown #2473` /
`Meta: ESP32-S3 binary-size reduction — Batch 1 (~26 KB) + Batch 2 (~26–50 KB) (supersedes #2771) #2773` cross-links.
ci/lint_cpp/test_cstdio_printf_checker.py— 26 unit testsmatching the existing
test_banned_macros_checker.pyshape.ci/lint_cpp/run_all_checkers.py— two-line registration(import + scope insertion).
Issue: #2773
🤖 Generated with Claude Code