一键导入
pow10-rule-02-bounded-loops
NASA Power of 10 Rule 2 — Every loop must have a statically determinable upper bound. Severity: blocker.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
NASA Power of 10 Rule 2 — Every loop must have a statically determinable upper bound. Severity: blocker.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | pow10-rule-02-bounded-loops |
| description | NASA Power of 10 Rule 2 — Every loop must have a statically determinable upper bound. Severity: blocker. |
Severity: blocker
Every loop must carry an explicit, statically verifiable upper bound on its iteration count. The bound should be a compile-time constant where possible. When the bound depends on runtime input, assert it against a fixed maximum.
Bounded loops make termination trivial to prove and worst-case execution time analyzable — required for Rate Monotonic Analysis in real-time systems. Unbounded loops are the most common source of runaway behavior in embedded code.
while (condition) with no enclosing iteration capfor (;;) loops outside an annotated main event looptake(N) capWrap any potentially-unbounded loop with an explicit counter capped by a compile-time constant. Combine with cancellation context (timeout, channel close, signal) so the loop exits cleanly when work is done.
main() event loops sometimes must be infinite. Tag them:
// pow10: allow rule=2 until=2099-01-01 owner=fsw-team reason="main event loop, intentional"
NASA Power of 10 Rule 1 — Restrict control flow to simple constructs (no goto, setjmp/longjmp, recursion). Severity: blocker.
NASA Power of 10 Rule 3 — No dynamic memory allocation after initialization. Severity: blocker.
NASA Power of 10 Rule 4 — Functions ≤60 lines (one printed page). Severity: high.
NASA Power of 10 Rule 5 — Average ≥2 runtime assertions per function. Severity: high.
NASA Power of 10 Rule 6 — Declare data at smallest possible scope. Severity: medium.
NASA Power of 10 Rule 7 — Check every non-void return value; validate every parameter. Severity: blocker.