Skip to content
Back to skills

Polyspace Justify Generated Code Findings

ASecurity

Use this skill to record Polyspace review decisions (status Justified or Not a defect, with a rationale) for Bug Finder or Code Prover findings in C/C++ code generated from a Simulink model: as a Polyspace annotation on the block the finding traces to, or as a comment in the model-link results database when there is no block. Use when asked to justify, suppress, accept, deviate, or mark as a false positive a MISRA C, MISRA C++, CERT C/C++, CWE, AUTOSAR C++14, defect, or run-time check finding...

  • 1,443 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
ai-agentsc++gitapidatabasedocumentation

Works with

  • api
  • mcp

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add matlab/simulink-agentic-toolkit --skill polyspace-justify-generated-code-findings --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Polyspace Justify Generated Code Findings?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Polyspace Justify Generated Code Findings
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/matlab-polyspace-justify-generated-code-findings/badge)](https://www.skillsdirectory.com/skills/matlab-polyspace-justify-generated-code-findings)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: polyspace-justify-generated-code-findings
description: >
  Use this skill to record Polyspace review decisions (status Justified or Not
  a defect, with a rationale) for Bug Finder or Code Prover findings in C/C++
  code generated from a Simulink model: as a Polyspace annotation on the block
  the finding traces to, or as a comment in the model-link results database
  when there is no block. Use when asked to justify, suppress, accept, deviate,
  or mark as a false positive a MISRA C, MISRA C++, CERT C/C++, CWE, AUTOSAR
  C++14, defect, or run-time check finding on generated code, including a
  request to add the justification comment in the generated code, or to change
  or remove such a justification. Never
  edits generated code. Not for deciding whether to fix or justify, re-running
  the analysis, handwritten C/C++, or Model Advisor justifications.
license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md
metadata:
  author: MathWorks
  version: "1.0"
---

# Justify Generated Code Findings with Polyspace

Store justifications in the model or in the results database, never in the
generated code: regeneration overwrites the code.

## When to Use

- Justify, suppress, accept, or mark as a false positive a Polyspace Bug Finder
  or Code Prover finding from a model-link analysis of code generated from a
  Simulink model (Embedded Coder)
- Record a deviation rationale for a MISRA C, MISRA C++, CERT C/C++, CWE,
  AUTOSAR C++14, defect, or run-time check finding on the block it traces to,
  or in the results when it has none
- Change or remove a Polyspace annotation on a block
- Add a Polyspace justification comment in the generated code: store it on the
  block or in the results instead, since regeneration deletes the comment
- Continue after `polyspace-review-generated-code-findings` decided which
  findings to justify, or after a verification run by
  `polyspace-analyze-generated-code`

## When NOT to Use

- No Polyspace analysis results present yet: use `polyspace-analyze-generated-code`
- Re-run the analysis while keeping or importing prior justifications or database comments: use `polyspace-analyze-generated-code`
- Decide whether a finding should be fixed or justified, or how to fix it: use `polyspace-review-generated-code-findings`
- To read and interpret results: use `polyspace-review-generated-code-findings`
- Justify or waive Model Advisor check results on the model: use `model-advisor-check-model-compliance`
- Justify uncovered logic with a coverage filter: use `simulink-explain-missing-coverage`
- Add a text note on the Simulink canvas: use `simulink-build-model`
- For handwritten or standalone C/C++ sources: use the Polyspace Agentic Toolkit
  skill `polyspace-justify-in-code` or `polyspace-justify-in-database`. If the
  toolkit is not installed, do not
  justify them and do not propose a comment to add by hand: say this skill
  covers only code generated from a Simulink model, and
  recommend installing the Polyspace Agentic Toolkit

## Prerequisites

- The Polyspace product that produced the results (Bug Finder or Code Prover),
  integrated with MATLAB and Simulink (`which("pslinkfun")` is not empty). Stop
  if not.
- The Polyspace Agentic Toolkit (Polyspace MCP server) is recommended for
  database comments. If `add_review_information_to_result` is available, use it
  where this workflow says so. If not, tell the user once that installing it is
  recommended (https://github.com/mathworks/polyspace-agentic-toolkit), and continue: model
  annotations need only MATLAB.

## Workflow

Choose where to store the comment:

- Use a model annotation when the finding has a `Sid` of a block (`model:12`).
- Otherwise, use a database comment. This includes Stateflow states and
  transitions (`model:12:3`): they cannot carry an annotation; annotating the
  whole chart block would cover all of the chart's code.

1. Reuse the loaded model, model-link project, and results. Do not create a project solely for a justification.
2. Identify the exact family, rule, message, location, status, and `Sid` of each finding — from the review handoff (results folder, `ID`, `Family`, `Check`, `Sid`) or from `getResults()` (not `getResults('readable')`, which has no `ID` or `Status` column). Bug Finder results have a `Sid` column; Code Prover results have the `Sid` only inside the `ToModel` link (`Simulink.ID.hilite('<sid>', ...)`, or `highlightBlock('<sid>', ...)` before R2026a). Before R2026a, Bug Finder results have no `Sid` and no block link: take the `sid` from the Polyspace Agentic Toolkit (`get_polyspace_results_list`); otherwise use the block the user names, after checking in the model that it exists and performs the operation the finding describes; otherwise treat the finding as having no `Sid`. Map the result to the annotation family and rule (see below).
3. For a Code Prover check, first apply the red and green rules in Conventions. Use status `Justified` for intentional deviations, or `Not a defect` for a false positive. Spell them exactly so: the status text is copied into the results as written. Never set `Justified` on a MISRA mandatory finding: the standard allows no deviation. `Not a defect` is allowed only for a proven false positive, with the evidence in the rationale. For a coding rule, a false positive means that the code does not break the rule; evidence that breaking it is harmless (value ranges, design intent) supports `Justified`, not `Not a defect`. If the evidence does not support the status the user asked for, propose the status that fits and ask; if you cannot ask, write nothing.
4. Write a brief and sound technical rationale from the prompt, deviation record, catalog, or available evidence. Never use only "false positive", never invent a rationale without user consent. If the user gave none, propose one and ask; if you cannot ask, report the proposed status and rationale and write nothing.
5. Add the comment and status - see next sections.
6. Confirm the result status and comment, considering its lifecycle properties.

### Add Comment and Status in Model
Use when `Sid` is present. Do not invent a block path.

First read the block's annotations with `model_query_params` (target
`blk_<n>`, where `<n>` is the number after the colon in the `Sid`; parameter
`PolySpaceStartComment`). If the rule is already annotated, update that line
instead (see Updating Comments or Status): `pslinkfun` always appends.

```matlab
pslinkfun('annotations', ...
    'type', family, ...
    'kind', rule, ...
    'block', blockSid, ...
    'status', 'Justified', ...   % or 'Not a defect'
    'comment', rationale);
```

`family` values, from the result's `Family`:

| Result `Family` | `family` |
|---|---|
| `Defect` | `DEFECT` |
| `Run-time Check` (Code Prover) | `RTE` |
| `MISRA C:2023` / `MISRA C:2012` | `MISRA-C-2023` / `MISRA-C3` |
| `MISRA C:2025` (R2026b and later) / `MISRA C:2004` (R2026a and earlier) | `MISRA-C-2025` / `MISRA-C` |
| `MISRA C++:2023` / `MISRA C++:2008` | `MISRA-CPP-2023` / `MISRA-CPP` |
| `SEI CERT C` / `SEI CERT C++` | `CERT-C` / `CERT-CPP` |
| `CWE`, `ISO/IEC TS 17961`, `AUTOSAR C++14`, `JSF AV C++`, `Guidelines`, custom rules | `CWE`, `ISO-17961`, `AUTOSAR-CPP14`, `JSF`, `GUIDELINE`, `CUSTOM` |

`rule`: result rule or checker identifier. For coding rules, the rule number at the start of `Check` (`10.4`, `INT30-C`); abbreviate `Dir 1.1` as `D1.1`. For CWE, the number only (`190`). For Code Prover, the `ID` column (`ZDV`, `OVFL`); before R2026a `ID` is a number, so take the acronym as for defects. For Bug Finder defects, the acronym (`INT_OVFL`): `getResults()` gives only the name in `Check`, so take the acronym from the Polyspace Agentic Toolkit (`get_polyspace_results_list`, field `check`) or from the defect's documentation page.

`pslinkfun` rejects an unknown family or rule ("Cannot resolve …"); then look the identifier up, do not retry with guesses. It does not check the status.

`rationale`: the comment to apply.

Then read `PolySpaceStartComment` back with `model_query_params` and check that the block has exactly one line for the rule, with the intended status and comment.

**Lifecycle:** A model annotation does not update existing results. Save the model, then re-run with `polyspace-analyze-generated-code` (it regenerates the code; annotations need no import) and verify the new result. If the results also hold database comments, ask it to import them from the current results folder (`ImportComments`).

Do not use a database comment solely because the model is dirty. For a traceable finding, annotate and save the model; tell the user about the model change.

### Add Comment and Status in Database
Use only when no block traceability is available. No MATLAB API writes review information.

**If the Polyspace Agentic Toolkit is installed**, use `add_review_information_to_result` to apply comment and status to a finding (`result_id` from `get_polyspace_results_list`, `results_file` = the `.psbf` or `.pscp` file in the results folder). The tool stores the status with the suffix `(with AI)` (`Justified (with AI)`), and Polyspace does not count the finding as justified until a person confirms it by setting the regular status. Tell the user which findings need that confirmation; do not report them as justified.

**Otherwise**, the user must add comments manually. Give the user a list of the findings with family, check, file, line, status, and rationale. If the user is present and asks for it, open the results in the GUI; never open it in an unattended run. Do not edit result objects, result files, or generated sources, and do not report these findings as justified.

```matlab
polyspaceBugFinder("-results-dir", resultsFolder);   % polyspaceCodeProver for Code Prover results
```

**Important**: When done, remind the user that the comments are stored in `ps_comments.db` in the results folder, and that the next analysis must import them: re-run with `polyspace-analyze-generated-code`, which keeps the previous folder and imports from it (`ImportComments`). Do not also run `transfer_polyspace_comments`.

**Database-comment lifecycle:** A comment or status written directly to the results database takes effect immediately for the current analysis. Do not regenerate code or rerun analysis merely to see the update.

### Updating Comments or Status
For a database update, use `add_review_information_to_result` when the Polyspace Agentic Toolkit is installed; otherwise give the user the change to make in the GUI.

To change or remove a model annotation, read `PolySpaceStartComment` and `PolySpaceEndComment` with `model_query_params`, then write them back with the `model_edit` configure operation on `blk_<n>`: replace or drop the lines of that rule (one `polyspace-begin` / `polyspace-end` line per annotation), keep the others. When no annotation is left, also clear `AttributesFormatString` if it is `Polyspace annotation` (the canvas label `pslinkfun` sets); keep any other value.

For example, with scope `root` (it reaches nested blocks) and `layout_mode`
`incremental`, operations as one line; join several lines with `\n`:

```json
[{"op":"configure","target":"blk_12","params":{"PolySpaceStartComment":"polyspace-begin RTE:OVFL [Not a defect:] \"Operands limited to +-1000 by the caller\"","PolySpaceEndComment":"polyspace-end RTE:OVFL [Not a defect:] \"Operands limited to +-1000 by the caller\""}}]
```

Read both parameters back with `model_query_params` to check the change, then save the model; the change reaches the results after the next run by `polyspace-analyze-generated-code`.

### After the Verification Run
When `polyspace-analyze-generated-code` reports back, load the new results and check status and comment of each justified finding. Match findings by family, check, and `Sid`, not by `ID`: result IDs change between runs. A status ending in `(with AI)` still needs a person's confirmation.

## Conventions

- Prefer a model fix or code-generation settings over justification: a justification hides the finding but keeps the behavior. If asked to justify a MISRA mandatory finding that is not a proven false positive, say so and offer a fix instead.
- Do not justify a red Code Prover check unless the user confirms after your warning: red means the error occurs on every execution, and Code Prover does not verify the code after it on that path. Say so, offer a fix instead, and write nothing until the user confirms; if you cannot ask, write nothing.
- To offer a fix, name `polyspace-review-generated-code-findings`: it proposes the model or code generation change. Do not work out the fix yourself.
- Justify only Code Prover checks that are not green: a green check is proven and an annotation on it has no effect.
- Version-control the model and, if used, the comments database.

## Common Mistakes

- Editing generated C/C++ sources or headers in any way: the next code generation overwrites them and the justification is lost
- Inventing a `Sid` or block path if not given in the results: the annotation lands on the wrong block or nowhere
- Editing `ps_comments.db` or results objects directly: Polyspace does not support it, and the comments can be lost
- Justifying a MISRA issue of type "mandatory" unless it is a False Positive
- Suppressing a finding without technical rationale: the justification cannot be reviewed
- Writing the status in another spelling (`justified`): it appears as written, not as the Polyspace status
- Calling `pslinkfun` again to change a justification: it adds a second line for the same rule

----

Copyright 2026 The MathWorks, Inc.

----

Files in this skill

  • SKILL.md13.3 KB
  • manifest.yaml651 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.