Repository navigation
Description
Context
fl::printf / fl::snprintf currently provide FastLED-owned formatting in src/fl/stl/stdio.h, and #3158 is migrating logging call sites toward FL_*_F(...) macros backed by fl::printf-style formatting. That makes the formatter a larger public surface area, so it needs better ergonomics and stronger failure-mode coverage.
Two gaps should be tracked separately from the logging migration:
- Generic placeholders: C++ callers often want to log arbitrary FastLED types without hand-selecting
%d,%u,%s, casts, or.c_str()conversions. Consider an idiomatic placeholder form, potentially{}for any supported variable, while preserving existing printf-style support where needed. - Mismatched argument safety: calls like
fl::printf("number: %d\n", "number")should not crash or read invalid memory. The formatter should degrade predictably, and tests should document the behavior.
Proposal
Enhance fl::printf / fl::snprintf so callers can use a generic placeholder for supported FastLED-printable values. {} is worth considering because it avoids pretending to be C printf when the implementation is type-aware C++ formatting, but the final syntax should fit the existing fl/stl/stdio.h design and embedded constraints.
Add comprehensive tests around malformed or surprising format strings and type mismatches. The goal is not necessarily to make every invalid call produce perfect output, but to guarantee bounded, deterministic behavior with no crashes, no invalid reads, and clearly documented fallback text.
Acceptance criteria
fl::printfandfl::snprintfsupport an idiomatic generic placeholder for common scalar/string/FastLED-owned types, with tests for at least integers, unsigned integers, bool, char, C strings,fl::string, pointers, and representative FastLED value types where supported by the formatter.- Existing
%-style behavior remains covered by tests and continues to work for current supported specifiers. - Type mismatch tests cover scenarios such as:
%dwith a string argument.%swith an integer argument.%pwith non-pointer and null pointer values.- too few arguments for placeholders.
- extra arguments after all placeholders are consumed.
- malformed specifiers such as a trailing
%, unknown%q, incomplete width/precision forms, and literal%%. - generic
{}with too few and extra arguments. - escaped braces or literal braces, if
{}is adopted.
- Wrong-type or malformed format calls have documented behavior and tests assert that behavior. At minimum they must not crash or read through invalid pointers.
- Tests live near the current formatter tests, such as
tests/fl/stl/stdio.cppand/ortests/fl/stl/cstdio.cpp, and include both direct string-buffer checks and print-path coverage where practical.
Open questions
- Should the generic placeholder be
{},%?, or another syntax that avoids conflict with existing percent-format behavior? - Should wrong-type
%placeholders emit a visible sentinel such as<format-error>, leave the placeholder unchanged, or format through the argument's generic string path? - Should compile-time checking be added for literal format strings where the implementation can reasonably do so without hurting embedded compatibility?
Related issues
- perf(log): migrate fl::sstream to printf-style backend for ~5-10 KB on ESP32-S3 (split from #3122 B2 / refs #2856 item 3.2) #3158 depends on wider
fl::printfusage for logging migration, so formatter ergonomics and mismatch safety directly affect that work.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(format): add generic {} placeholder to fl::printf/snprintf (#3174)…