Skip to content

feat(lint): ban bare printf/vprintf in src/ + replace last 13 WASM offenders with fl::printf - #2888

Merged
zackees merged 1 commit into
masterfrom
feat/ban-bare-printf-family
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/ban-bare-printf-family

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes the long tail of FastLED #2773 item 1.1/1.5 — the printf-family elimination work — by:

  1. Extending ci/lint_cpp/bare_snprintf_checker.py to ban bare printf and vprintf (previously only the snprintf/sprintf/fprintf branches were on the list).
  2. Replacing 13 bare printf(…) call sites in WASM platform code with fl::printf(…).
  3. Suppressing 2 false-positive method-declaration sites with // ok snprintf.

After this PR, src/ has zero bare references to the C printf family per the goal in #2886.

Why

fl::printf (defined at src/fl/stl/stdio.h:37) formats through fl::sstream and avoids pulling newlib's _vfprintf_r engine into the binary. Banning the C variants library-wide is the only way to prevent future drift.

Changes by file

File Change
ci/lint_cpp/bare_snprintf_checker.py Add printf, vprintf to BANNED_FUNCS.
src/platforms/wasm/audio_input_wasm.cpp.hpp 5 sites — lines 101, 113, 163, 166, 221.
src/platforms/wasm/fs_wasm.cpp.hpp 1 site (344) + new #include "fl/stl/stdio.h".
src/platforms/wasm/js_bindings.cpp.hpp 7 sites — lines 186, 226, 327, 333, 352, 387, 392.
src/fl/system/serial.h Suppress declaration at line 180 (body already routes via fl::snprintf).
src/platforms/stub/Arduino.h Suppress declaration at line 191 (forwards to fl::printf).

Test plan

Out of scope

This PR does not flip the FASTLED_LOG_VERBOSITY default — that's Stage 1 of #2886 and gets its own PR. This PR only enforces "no bare C printf family" so when Stage 1 lands, it doesn't have any FL_WARN sites that secretly reach the C printf engine.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Expanded code linting checker to identify and flag additional unsafe C standard library function calls that were previously undetected across the codebase.
    • Standardized internal logging statements across multiple platform-specific implementations and system components to consistently use designated library functions rather than direct standard library calls.

…fenders with fl::printf

## What

Closes the long tail of the FastLED #2773 item 1.1 / 1.5 work.

1. **Extend `ci/lint_cpp/bare_snprintf_checker.py`** to also ban bare
   `printf` and `vprintf` — previously only the snprintf/sprintf/
   fprintf branches were on the list, leaving raw `printf(...)` calls
   uncaught.

2. **Replace 13 bare `printf(...)` call sites** under `src/platforms/wasm/`
   with `fl::printf(...)`:
   - `src/platforms/wasm/audio_input_wasm.cpp.hpp` — 5 sites (lines 101,
     113, 163, 166, 221)
   - `src/platforms/wasm/fs_wasm.cpp.hpp` — 1 site (line 344) +
     `#include "fl/stl/stdio.h"`
   - `src/platforms/wasm/js_bindings.cpp.hpp` — 7 sites (lines 186, 226,
     327, 333, 352, 387, 392; already had the include)

3. **Suppress 2 false-positive method declarations** with `// ok snprintf`:
   - `src/fl/system/serial.h:180` — `SerialPort::printf(...)` declaration;
     body at line 284 already routes through `fl::snprintf`.
   - `src/platforms/stub/Arduino.h:191` — stub `printf` method that
     forwards to `fl::printf`.

## Why

The FastLED #2773 audit landed `fl::snprintf` (#2775) and the
existing `bare_snprintf_checker.py` lint guard, but the lint banned
`snprintf/sprintf/vsnprintf/vsprintf/fprintf/vfprintf` and missed bare
`printf`. WASM code accumulated 13 bare `printf(...)` calls; now
fixed and lint-enforced going forward.

`fl::printf` (from `src/fl/stl/stdio.h:37`) is a template that
formats via `fl::sstream` and avoids pulling newlib's `_vfprintf_r`
engine.

## Verification

- `uv run python ci/lint_cpp/bare_snprintf_checker.py` → 0 violations.
- `bash lint --cpp` → all checks pass.
- `bash bloat esp32s3` → 388,380 B flash unchanged (WASM files are
  `#ifdef FL_IS_WASM`-gated; ESP32-S3 doesn't link them, so the bloat
  metric is identical pre/post change, as expected).
- `bash test --cpp` could not validate from inside the worktree due to
  the meson-encoded-source-path bug filed at #2887; the same test
  passes on the main checkout against this exact diff at HEAD.
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7cba574e-098f-467f-8f05-d9d9bb499b29

📥 Commits

Reviewing files that changed from the base of the PR and between f013443 and ba6471d.

📒 Files selected for processing (6)
  • ci/lint_cpp/bare_snprintf_checker.py
  • src/fl/system/serial.h
  • src/platforms/stub/Arduino.h
  • src/platforms/wasm/audio_input_wasm.cpp.hpp
  • src/platforms/wasm/fs_wasm.cpp.hpp
  • src/platforms/wasm/js_bindings.cpp.hpp

📝 Walkthrough

Walkthrough

This PR expands the bare C printf-family function ban to include printf and vprintf, updating the linter rule and migrating all corresponding unqualified calls throughout WASM platform code to use the fl::printf wrapper instead.

Changes

Printf-family function ban enforcement and migration

Layer / File(s) Summary
Lint rule expansion
ci/lint_cpp/bare_snprintf_checker.py
The BANNED_FUNCS list now includes printf and vprintf alongside the existing banned printf-family functions, enforcing the ban on unqualified C-style printf calls.
Printf wrapper interface clarification
src/fl/system/serial.h, src/platforms/stub/Arduino.h
Clarifying inline comments are added to SerialPort::printf and SerialEmulation::printf template declarations documenting their routing through fl::printf and fl::snprintf.
WASM platform printf migration
src/platforms/wasm/fs_wasm.cpp.hpp, src/platforms/wasm/audio_input_wasm.cpp.hpp, src/platforms/wasm/js_bindings.cpp.hpp
Bare printf calls are systematically replaced with fl::printf throughout WASM code: filesystem file-declaration logging, audio input block and sample logging, and UI bridge event logging; a new fl/stl/stdio.h include is added to fs_wasm.cpp.hpp.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • FastLED/FastLED#2775: Both PRs modify the bare printf-family lint rule in ci/lint_cpp/bare_snprintf_checker.py to govern detection and enforcement of qualified printf usage; the retrieved PR introduces the initial checker, and this PR extends it to ban printf and vprintf.

Poem

A rabbit hops through printf calls with glee,
Wrapping them up in fl:: spree,
The linter now watches both printf and vprintf too,
WASM logs shine with proper routing through,
No bare calls left—they're all enshrined! 🐰✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ban-bare-printf-family

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 600786d into master Jun 7, 2026
6 of 7 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 7, 2026
@zackees
zackees deleted the feat/ban-bare-printf-family branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant