Skip to content
BENIBIX Learn

Control Flow Graph (CFG)

Development🕸️ Code IntelligenceCode Graphs

Also known as CFG, Flow Graph

A map of each path a function can take. It splits at each if and loop.

Think of it like

It is like a maze map. It shows each path you could walk, and where the paths split.

Example

A tool reads the control flow graph of a login function. It finds one path where the password check is skipped.

Why it matters

Bugs hide on paths nobody tested. The graph shows every one of them.

Definition

A control flow graph shows every path a program can take through one function. Each box is a run of steps with no choice in it. An arrow leads to the next box. An if or a loop makes the arrows split or circle back. Tools read it to find code no path can reach, or a path that skips a check.
The control flow graph, on the right: every path through one function.

Common mistake

Thinking each path is tested because each line is. Two ifs make four paths, and tests often cover only two.

Key takeaways

  1. 1
    Boxes of steps. No choices inside a box.
  2. 2
    Splits at choices. Each if or loop branches.
  3. 3
    Every path. Even the ones you never run.

Compare