# Static analysis

Static analysis examines source code without running it and reports
findings. The family ranges from cheap pattern-matching linters to
heavyweight whole-program dataflow analyzers.

Every method here works the same way: it checks the code against a rule
or invariant. Most report likely problems with high confidence rather
than a proof; the exceptions are the checks decided outright over a
single procedure's control flow or dataflow, where the finding is a fact
about the code. What separates the sub-families is *how deep they look*
and *what they look for*.

## The sub-families

- **[Linters](https://quality.stereobooster.com/linters.md)**: per-language, pattern- and rule-based bug
  finders run at diff time. Off-by-one, missing `await`, suspicious
  cast, API misuse. Fast, high-volume, tuned to keep false positives low.
- **[Deep static analysis](https://quality.stereobooster.com/deep-static-analysis.md)**: cross-language
  query and dataflow engines ([CodeQL](https://codeql.github.com),
  [Semgrep](https://semgrep.dev/)), and automaton analysis of regular
  expressions. Builds a model of the program and queries it, rather than
  matching a pattern in one file.
- **[Secret scanning](https://quality.stereobooster.com/secret-scanning.md)**: rule- and entropy-matching
  over unparsed text, reaching the whole git history rather than only the
  current tree.
- **[Dead-code detection](https://quality.stereobooster.com/dead-code-detection.md)**: code no execution
  can reach — unused files, exports, and dependencies from the call
  graph, plus unreachable statements, branches no input can satisfy, and
  values assigned and never read.
- **[Clone detection](https://quality.stereobooster.com/clone-detection.md)**: near-duplicate fragments
  across the codebase, above a tuned similarity threshold.
- **[Database migration safety](https://quality.stereobooster.com/migration-safety.md)**: linting schema
  migrations for locks and backward-incompatible changes that break a
  rolling deploy.

## What the family catches

Each sub-page covers its own bug classes; several defect classes are
themselves whole sub-families with dedicated pages:

- **Memory-safety bugs.** Buffer overflow, use-after-free, double-free,
  null deref. Tools targeting C/C++ are strongest here; the depth
  argument is on [memory safety](https://quality.stereobooster.com/memory.md).
- **Concurrency bugs.** Data races, deadlocks, missing locks. Facebook's
  [Infer](https://fbinfer.com/) checks for them; the method sits on
  [concurrency](https://quality.stereobooster.com/concurrency.md).
- **Security taint.** User input reaching a dangerous sink (SQL, shell,
  eval, file path). Interprocedural source→sink dataflow is a distinct
  sub-family: [taint analysis](https://quality.stereobooster.com/taint-analysis.md).
- **Committed secrets.** Credentials in the tree or anywhere in history:
  [secret scanning](https://quality.stereobooster.com/secret-scanning.md).
- **ReDoS and API misuse.** Statically detectable, covered under
  [deep static analysis](https://quality.stereobooster.com/deep-static-analysis.md) and
  [linters](https://quality.stereobooster.com/linters.md).
- **Deadness and duplication.** Code nothing can reach, and code that
  exists twice: [dead-code detection](https://quality.stereobooster.com/dead-code-detection.md) and
  [clone detection](https://quality.stereobooster.com/clone-detection.md).

## When to use, when not

**Use:**

- Diff-time deployment, posting results inline as PR comments.
- High signal-to-noise rule selection. A small, high-confidence initial
  ruleset is easier to expand than to cut back.
- Memory-safety-sensitive C/C++ code, where the heavyweight analyzers
  earn their cost.

**Don't:**

- Treat static analysis as a complete verification toolkit. It catches
  *patterns* and *reachable dataflow*; it misses *logic*. Generative
  methods (property tests, [fuzzing](https://quality.stereobooster.com/fuzzing.md)) and [code
  review](https://quality.stereobooster.com/code-review.md) handle what it can't.
- Drown developers in warnings. Across studies the deciding factor for
  adoption is the false-positive rate and whether developers trust the
  output, not the algorithm (Bessey et al. 2010; Li et al. 2024)[^bessey2010] [^li2024].

## Evidence

How much of what these tools report gets acted on — the adoption
economics — has consistent answers across four decades of studies, and
they hold for every method in the family:

- **Coverity at scale.** A retrospective across ~700 customer codebases
  found the false-positive rate and whether developers understand and
  trust the output to be the deciding factors for adoption (Bessey et al. 2010)[^bessey2010].
- **Facebook Infer and Zoncolan.** Diff-time deployment jumped the fix
  rate from near-zero (batch) to over 70%; developers have resolved over
  100,000 Infer-flagged issues since 2014, across codebases of tens of
  millions of lines (Distefano et al. 2019)[^distefano2019].
- **FindBugs at Google.** In the May 2009 company-wide fixit, 282
  engineers filed 10,479 reviews across 3,954 of 9,473 open issues, over
  77% of reviews classified the warning as a real defect worth fixing,
  and submitted changes removed more than 1,000 issues (Ayewah and Pugh 2010)[^ayewah2010].
  Reviewers chose what to review and concentrated on the Correctness
  category — 71% of those issues reviewed against 17% of the rest — so
  77% is a rate over self-selected warnings, not over all warnings.

How much of what exists gets reported, and what those reports were worth,
answer far less well:

- **Yield is not recall.** A count of issues actioned measures precision
  times scale times time, not the share of real bugs a tool finds.
  Against fixed bug sets, three detectors found 4.5% of 594 real Java
  bugs (Habib and Pradel 2018)[^habib2018] and six C/C++ analyzers missed 47–80% of 192 real
  vulnerabilities (Lipp et al. 2022)[^lipp2022]. A low-recall analyzer run continuously
  over an enormous codebase still accumulates six figures of fixes. Both
  results hold; neither substitutes for the other.
- **Measured recall is a floor, not an estimate.** The bug sets are drawn
  from defects committed to version control, so any bug a detector caught
  before check-in is missing from the sample by construction — a caveat
  the authors state themselves (Habib and Pradel 2018)[^habib2018]. What a diff-time deployment
  prevents is therefore higher than the measured figure, by an unmeasured
  amount.
- **A real defect is not a production incident.** In the Google fixit,
  none of the serious bugs turned out to be associated with serious
  incorrect behavior in production: they sat in code not yet pushed, or
  not executed, or executed in conditions that misbehaved only subtly —
  performance degradation and the like (Ayewah and Pugh 2010)[^ayewah2010]. The authors
  attribute this to Google's testing and monitoring catching those
  problems by other means rather than to any failure of the analysis, and
  put the value of FindBugs in finding them earlier, where remediation is
  cheap. Static analysis competing against strong testing buys *time*,
  which is a weaker and more contingent claim than catching what nothing
  else would.

The per-method numbers, including the security-specific ones, are on
[deep static analysis](https://quality.stereobooster.com/deep-static-analysis.md) and
[secret scanning](https://quality.stereobooster.com/secret-scanning.md).

## Referenced by

- [Maintainability](https://quality.stereobooster.com/maintainability.md) · Quality dimensions
- [Quality dimensions](https://quality.stereobooster.com/quality-dimensions.md) · Quality dimensions
- [Guarantee](https://quality.stereobooster.com/guarantee.md) · The axes
- [Code review](https://quality.stereobooster.com/code-review.md) · Methods
- [Deep static analysis](https://quality.stereobooster.com/deep-static-analysis.md) · Methods
- [Example tests](https://quality.stereobooster.com/example-tests.md) · Methods
- [Linters](https://quality.stereobooster.com/linters.md) · Methods
- [Penetration testing](https://quality.stereobooster.com/penetration-testing.md) · Methods
- [Supply-chain hygiene](https://quality.stereobooster.com/supply-chain-hygiene.md) · Methods
- [Taint analysis](https://quality.stereobooster.com/taint-analysis.md) · Methods
- [Threat modeling](https://quality.stereobooster.com/threat-modeling.md) · Methods
- [ESLint](https://quality.stereobooster.com/eslint.md) · Recipes
- [How AI fits into software quality](https://quality.stereobooster.com/ai.md) · AI
- [Choosing methods](https://quality.stereobooster.com/choosing.md) · Overview

## References

[^bessey2010]: Bessey, Al, Ken Block, Ben Chelf, et al. 2010. "[A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World](https://web.stanford.edu/~engler/BLOC-coverity.pdf)." *Communications of the ACM* 53 (2): 66–75. <https://doi.org/10.1145/1646353.1646374>.
[^li2024]: Li, Chunmiao, Yijun Yu, Haitao Wu, Yuanliang Zhang, Zhi Jin, and Zhenjiang Hu. 2024. "[Unleashing the Power of Clippy in Real-World Rust Projects](https://arxiv.org/pdf/2310.11738)." *Proceedings of the 2024 IEEE/ACM 46th International Conference on Software Engineering: Companion Proceedings*, 318–19. <https://doi.org/10.1145/3639478.3643096>.
[^distefano2019]: Distefano, Dino, Manuel Fähndrich, Francesco Logozzo, and Peter W. O'Hearn. 2019. "[Scaling Static Analyses at Facebook](https://cseweb.ucsd.edu/~dstefan/cse227-spring20/papers/distefano:scaling.pdf)." *Communications of the ACM* 62 (8): 62–70. <https://doi.org/10.1145/3338112>.
[^ayewah2010]: Ayewah, Nathaniel, and William Pugh. 2010. "[The Google FindBugs Fixit](https://dl.acm.org/doi/pdf/10.1145/1831708.1831738)." *Proceedings of the 19th International Symposium on Software Testing and Analysis (ISSTA '10)* (New York), 241–52. <https://doi.org/10.1145/1831708.1831738>.
[^habib2018]: Habib, Andrew, and Michael Pradel. 2018. "[How Many of All Bugs Do We Find? A Study of Static Bug Detectors](https://software-lab.org/publications/ase2018_static_bug_detectors_study.pdf)." *Proceedings of the 33rd ACM/IEEE International Conference on Automated Software Engineering (ASE '18)*, 317–28. <https://doi.org/10.1145/3238147.3238213>.
[^lipp2022]: Lipp, Stephan, Sebastian Banescu, and Alexander Pretschner. 2022. "[An Empirical Study on the Effectiveness of Static C Code Analyzers for Vulnerability Detection](https://mediatum.ub.tum.de/doc/1659728/1659728.pdf)." *Proceedings of the 31st ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA 2022)*, 544–55. <https://doi.org/10.1145/3533767.3534380>.
