</>EmbeddedInterview

What is static analysis and which tools are used?

EasyDebugging, Testing & Tools

Short answer: Static analysis examines source code without running it to find bugs and rule violations: NULL dereferences, buffer overruns, uninitialised variables, integer overflow, resource leaks, dead code, concurrency issues and violations of coding standards such as MISRA C. It runs in CI on every change and catches issues that tests miss because they occur only on rare paths.

Tool Type
Compiler warnings (-Wall -Wextra -Wshadow -Wconversion -Wcast-align -Werror), GCC -fanalyzer free, first line of defence
clang-tidy, Clang Static Analyzer (scan-build) free, deep path analysis
cppcheck free, low false positives, MISRA addon
Coverity, Klocwork, Polyspace, PC-lint Plus, Parasoft C/C++test, Helix QAC commercial, MISRA/CERT checking, certification support
CodeQL, SonarQube queries, dashboards
Polyspace Code Prover, Frama-C, Astrée abstract interpretation: prove absence of some run-time errors
Stack analysis (-fstack-usage, puncover), WCET tools (aiT) resource bounds

Coding standards: MISRA C:2012/2023 (automotive, industrial; rules with mandatory/required/advisory categories and a deviation process), CERT C (security), AUTOSAR C++14 / MISRA C++:2023, and the Barr Group Embedded C Coding Standard.

Making it work in practice: start with compiler warnings as errors; add one analyser to CI; fix or explicitly suppress (with a justification) each finding so the baseline stays clean; run analysis on new code first for legacy codebases.

Dynamic analysis complements it: sanitizers (ASan, UBSan, TSan) and Valgrind on host builds, fuzzing (libFuzzer, AFL++) for parsers and protocol handlers.