AI Skill Report Card

Analyzing MISRA C Compliance

A-88·Nov 25, 2026·Source: Web
14 / 15

Given a C source file, run the four-stage pipeline:

  1. Ingest the C code (preserve line numbers exactly — they are load-bearing for all downstream steps).
  2. Detect violations → emit JSON array matching the schema below.
  3. Remediate each violation → emit a minimal compliant patch.
  4. Verify each patch → confirm it (a) resolves the original violation, (b) introduces no new MISRA violations, and (c) preserves the surrounding code's style/idioms.

Never skip straight to patching without first producing the Step 2 JSON — it is the audit trail every later step depends on.

Recommendation▾
Add an example showing a low-confidence/ambiguous case to demonstrate the 0.3-0.59 calibration tier in practice
14 / 15
Progress:
- [ ] Step 1: Ingest & line-index the C source
- [ ] Step 2: Detect violations, emit JSON report
- [ ] Step 3: Generate compliant patch per violation
- [ ] Step 4: Verify patch (compliance + style preservation)

Step 1 — Ingest

  • Keep the source verbatim; do not reformat before analysis (reformatting shifts line numbers and invalidates start_line_of_error/end_line_of_error).
  • If the file has no trailing newline or unusual tabs, note it internally — this affects line counting.

Step 2 — Violation Detection

For each violation found, emit one JSON object with exactly these fields:

FieldTypeNotes
rankint 1–5Severity-ish ordering; 1 = highest priority to fix first
rule_idstring"MISRA C:2025 Rule X.Y"
start_line_of_errorintFirst line of the relevant span
end_line_of_errorintLast line of the relevant span
identified_bugstringExact offending code text (copy verbatim, don't paraphrase)
identified_lineintSingle representative line within the span
suspicious_syntaxstringThe exact token: variable name, cast expression, function name, or operator
reasoningstring1–2 sentences, written for a downstream rule-checking tool, not a human narrative
confidencefloat 0.0–1.0Calibrated — do not default to 0.9 for everything

Output as a JSON array, one object per violation, sorted by start_line_of_error ascending. If zero violations, output [] — never omit the array.

Confidence calibration rule of thumb:

  • 0.9–1.0: unambiguous syntactic violation (e.g., implicit int-to-pointer cast)
  • 0.6–0.89: pattern-matches a rule but context-dependent (e.g., recursion, dynamic memory)
  • 0.3–0.59: plausible but requires knowledge the snippet doesn't fully provide (e.g., cross-TU linkage)

Step 3 — Patch Generation

For each violation (process by rank, then by start_line_of_error):

  1. Quote the minimal surrounding block needed for a valid patch (prefer function-scope, not whole-file).
  2. Produce a diff-style or before/after snippet that fixes only that violation — don't bundle unrelated cleanup.
  3. State which rule_id the patch addresses.
  4. If a single fix would resolve multiple reported violations, note the overlap explicitly rather than duplicating the patch.

Step 4 — Verification (Research Point)

This is the step most pipelines skimp on — do not skip it.

For every patch produced in Step 3, check:

  1. Compliance regression check: re-scan the patched snippet (mentally re-run Step 2's logic) against the full rule set, not just the original rule_id. A fix for Rule 10.3 (implicit conversion) can easily introduce a Rule 17.7 (ignored return value) violation.
  2. Original violation resolved: confirm the identified_bug text no longer appears in the offending form.
  3. Style preservation: compare against surrounding code for:
    • Naming convention (snake_case vs camelCase, Hungarian prefixes)
    • Brace style and indentation width
    • Preferred idioms already used in the file (e.g., if the file always uses (void) casts to discard return values, the patch should too)
    • Comment density/style
  4. Semantic equivalence: the patch must not change observable behavior unless the violation is the behavior (e.g., undefined behavior fixes legitimately change semantics — note this explicitly).

Emit a verification verdict per patch:

JSON
{ "rule_id": "MISRA C:2025 Rule 10.3", "patch_accepted": true, "new_violations_introduced": [], "style_preserved": true, "notes": "Explicit cast added matches existing style of explicit casts elsewhere in file (line 42)." }

If patch_accepted is false, loop back to Step 3 with the reason appended as a constraint.

Recommendation▾
The 'allowed set of seven' rules mentioned in Common Pitfalls is never defined elsewhere in the skill — include the actual rule list or clarify where it comes from
17 / 20

Example 1:

Input (excerpt, line 14):

C
int *p = 0x1000;

Step 2 output:

JSON
{ "rank": 1, "rule_id": "MISRA C:2025 Rule 11.4", "start_line_of_error": 14, "end_line_of_error": 14, "identified_bug": "int *p = 0x1000;", "identified_line": 14, "suspicious_syntax": "0x1000", "reasoning": "An integer constant is converted to a pointer type without an explicit cast, which Rule 11.4 flags as a conversion requiring scrutiny.", "confidence": 0.95 }

Step 3 patch:

C
int *p = (int *)0x1000; /* explicit cast per MISRA Rule 11.4 */

Step 4 verdict:

JSON
{ "rule_id": "MISRA C:2025 Rule 11.4", "patch_accepted": true, "new_violations_introduced": [], "style_preserved": true, "notes": "Comment style matches existing inline MISRA annotations in the file." }

Example 2 (overlap case):

Input has two reported violations on the same line — Rule 10.1 (operand type) and Rule 10.4 (essential type mismatch in arithmetic) both pointing at result = flag + count; where flag is bool and count is int.

Step 3 output notes: "Single patch resolves both Rule 10.1 and Rule 10.4 — casting flag to int explicitly makes the essential types compatible for the arithmetic." Patch: result = (int)flag + count;

Recommendation▾
Add a worked example of a Step 4 rejection (patch_accepted: false) and the resulting loop-back to Step 3 to fully illustrate the verification feedback loop
  • Always copy identified_bug text verbatim from source — never paraphrase or reformat it, downstream tools may string-match it.
  • Keep patches minimal and single-purpose; reviewers trust small diffs more than large rewrites.
  • When uncertain between two rule IDs for the same symptom, report both as separate JSON objects rather than guessing one.
  • Preserve the original author's variable names and structure unless the violation itself is the naming (e.g., Rule 5.x identifier rules).
  • Treat Step 4 as a second, independent pass — don't assume a patch is correct just because it was generated to look correct.
  • Don't shift or recompute line numbers after reformatting — always index against the original input.
  • Don't emit confidence: 1.0 as a default; reserve it for truly mechanical, unambiguous cases.
  • Don't bundle multiple unrelated fixes into one patch "for efficiency" — this breaks traceability to rule_id.
  • Don't skip Step 4 or treat it as a rubber stamp — the most common pipeline failure is a patch that fixes the reported rule but silently violates another.
  • Don't invent a rule ID not in the allowed set of seven; if no allowed rule fits, lower confidence and say so in reasoning rather than forcing a match.
  • Don't change code style wholesale (e.g., reformatting braces) as a side effect of a MISRA fix — this fails the style-preservation check in Step 4.
0
Grade A-AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
14/15
Workflow
14/15
Examples
17/20
Completeness
17/20
Format
15/15
Conciseness
13/15