Memory Safety c Skill.instructions
<!-- SPDX-License-Identifier: MIT -->
<!-- Copyright (c) PromptKit Contributors -->
---
description: 'Memory safety analysis for C code — allocation pairing, pointer lifecycle, buffer bounds, and undefined behavior checks'
applyTo: '**/*.c, **/*.h'
---
<!-- Generated by PromptKit — edit with care -->
When reviewing or analyzing C code, apply the following checks in order.
For every claim, finding, or recommendation, you MUST distinguish:
- **KNOWN**: directly observed in code, logs, or documentation
- **INFERRED**: logically derived from KNOWN facts
- **ASSUMED**: stated for clarity but not yet confirmed
Do not present INFERRED or ASSUMED conclusions as KNOWN facts. When uncertain,
say so explicitly rather than guessing.
## Phase 1 — Allocation and Deallocation Pairing
- Identify every allocation site (malloc, calloc, realloc, custom allocators).
- Trace each allocation to its deallocation site.
- Flag any path where deallocation is missing, occurs multiple times, or
occurs in a different lifetime scope than the allocation.
## Phase 2 — Pointer Lifecycle
- Identify every pointer that is passed across a function boundary, stored in
a struct, or returned from a function.
- Verify the pointed-to object outlives all pointer uses.
- Flag any pointer that may be used after its referent is freed or goes
out of scope.
## Phase 3 — Buffer Boundaries
- Identify every read or write through a pointer with an associated length.
- Verify the length is validated before use.
- Flag any access that may exceed the allocated size.
## Phase 4 — Undefined Behavior
- Flag signed integer overflow, invalid pointer arithmetic, uninitialized
reads, and type-punning that violates strict aliasing.
- Label each finding with KNOWN, INFERRED, or ASSUMED per the epistemic
labeling rules above.
## Project Context
**Focus**: Stack lifetime hazards at driver/kernel boundaries.
Every finding must cite an exact code excerpt with file path and line
numbers. Do not report findings you cannot cite directly.when to use it
Community prompt sourced from the open-source GitHub repo microsoft/PromptKit (MIT). A "Memory Safety c Skill.instructions" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
roleplaycommunitygeneral
source
microsoft/PromptKit · MIT