Notes / Firmware Design & Quality
Static analysis: finding bugs before running
Turn compiler warnings all the way up, and find defects without executing the code using cppcheck and clang-tidy.
Stage 1: compiler warnings
-Wall -Wextra -Wshadow -Wconversion -Wdouble-promotion -Werror
-Wconversion: implicit narrowing conversions (int → uint8_t)-Wdouble-promotion: float calculations accidentally becoming double (very slow on an M4, whose FPU is single precision only)-Werror: turns warnings into errors so they cannot pile up
Keeping zero warnings is by itself the cheapest form of quality control.
Stage 2: static analysis tools
| Tool | Characteristics |
|---|---|
| cppcheck | Free; null pointers, array bounds, uninitialised variables |
| clang-tidy | Free; many rules, automatic fixes |
| PC-lint / Polyspace / QAC | Commercial; MISRA, automotive certification projects |
What they catch
- Use of an uninitialised variable
- An index beyond array bounds
- Paths where a null pointer may be dereferenced
- Use after free, memory leaks
- Unreachable code, conditions that are always true
Running it
Do not try to fix every warning at once. Set a baseline, keep new code at zero, and check automatically in CI. Suppress false positives with a comment giving the reason.