memory-safe-c-cpp

memory-safe-c-cpp is a skill for Claude Code, Codex from mohitmishra786/low-level-dev-skills. It costs 147 tokens per session (2,850 once invoked), scanned A, original, MIT.

A guide to adding safety protections to existing C and C++ programs without immediately rewriting them. It compares compiler options, safer allocators, memory tagging, and alternatives such as rewriting code in Rust.

In plain words
What is it for?
Use it to choose and enable hardening measures, compare them with testing tools such as AddressSanitizer, and decide whether to harden in place or rewrite.
Why use it?
C and C++ can suffer from buffer overflows, use-after-free errors, and other memory bugs. The guide explains which protections catch which bug types and where they do not help.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Needs its repository: it runs a file that does not travel with it, so clone the repository first. The line is ./build/bin/filcc -O2 -o app app.c # also fil++ for C++.

Good fit Use it to choose and enable hardening measures, compare them with testing tools such as AddressSanitizer, and decide whether to harden in place or rewrite.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/mohitmishra786/low-level-dev-skills
agentmods
npx agentmods add skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for memory-safe-c-cpp

README.md
[![agentmods](https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp/github.svg)](https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp)
Your own site
<a href="https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp"><img src="https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for memory-safe-c-cpp

Your own site · 80×15
<a href="https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp"><img src="https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/memory-safe-c-cpp.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 147 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,850 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00147 $0.02850
Opus 5.5 $0.00059 $0.01140
Sonnet 5.5 $0.00029 $0.00570
Haiku 4.5 $0.00015 $0.00285

Measured 14d ago against content hash e89e4e966110, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

memory-safe-c-cpp scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 14d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/security/memory-safe-c-cpp/SKILL.md · 220 lines

How it starts

The opening of the file, as written. The whole thing — 220 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Memory-Safe C and C++

Purpose

Guide agents through making existing C and C++ safer (checked with GCC 16.2, Clang 23.1 and Fil-C 0.687): what each mitigation actually catches, how to enable it, and when a rewrite is the better answer.

Triggers

  • "How do I harden a C codebase without rewriting it?"
  • "What does -fhardened turn on?"
  • "Does FORTIFY catch heap overflows?"
  • "How do I use Arm MTE or a hardened allocator?"
  • "What is Fil-C and should I use it?"
  • "Harden, sanitize, or rewrite in Rust?"

Workflow

1. What catches what

Measured on one program with a heap overflow (writing 17 bytes into malloc(16)), a use-after-free read and a strcpy into char small[8]:

Build Heap OOB write UAF read strcpy stack overflow
gcc -O2 not caught not caught not caught
gcc -O2 -fhardened not caught not caught caught (*** buffer overflow detected ***)
Scudo allocator (clang -fsanitize=scudo) not caught (slack in chunk) not caught n/a; double free caught
Fil-C caught (filc safety error) caught caught when it leaves the allocation
ASan (testing only) caught caught caught

Mitigations that run in production reduce exploitability; they do not find all bugs. Use sanitizers and fuzzing in CI, and a safe language or Fil-C where you need guarantees.

Goal?
├── Cheap, ship today → -fhardened + library hardening + -ftrivial-auto-var-init (sections 2-3)
├── Catch bounds bugs on flexible arrays → counted_by + -fsanitize=bounds (section 4)
├── Probabilistic detection in production on Arm → MTE (section 5)
├── Heap metadata attacks → hardened allocator (section 6)
├── Full memory safety, accept slowdown → Fil-C (section 7) or CHERI hardware (section 8)
└── New component → write it in Rust (skills/rust/rust-ffi for the boundary)

2. -fhardened and friends (GCC 14+)

gcc -O2 -fhardened app.c -o app

On GCC 16.2 (aarch64) -fhardened defines _FORTIFY_SOURCE=3, _GLIBCXX_ASSERTIONS, enables -fstack-protector-strong (__SSP_STRONG__), PIE, and links with -pie -z now -z relro. On x86 it also enables -fcf-protection=full (__CET__ = 3). Without optimization FORTIFY is skipped: '_FORTIFY_SOURCE' is not enabled by '-fhardened' because optimizations are turned off.

Read the full file on GitHub · 220 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 14d ago First seen · 220 lines · 147 tokens per session scan A e89e4e966110

Subscribe to this mod's changes

memory-safe-c-cpp is a skill published in the GitHub repository mohitmishra786/low-level-dev-skills (310 stars, last pushed 14d ago), licensed MIT. It adds 147 tokens to every session and 2,850 once invoked, about $0.0006 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-21.

Related

memory-safe-c-cpp compared with skills from other repositories

memory-safe-c-cpp next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
memory-safe-c-cppmohitmishra786/low-level-dev-skillsSkill31014d agoMITA147Claude Code, Codex
ecommerce-marketing-strategy-buildernexscope-ai/eCommerce-SkillsSkill1.6ktodayMITA112Claude Code, Codex
product-description-generatornexscope-ai/eCommerce-SkillsSkill1.6ktodayMITA126Claude Code, Codex
shopify-marketingnexscope-ai/eCommerce-SkillsSkill1.6ktodayMITA60Claude Code, Codex
tiktok-shop-cross-bordernexscope-ai/eCommerce-SkillsSkill1.6ktodayMITA55Claude Code, Codex
ecommerce-landing-pagenexscope-ai/eCommerce-SkillsSkill1.6ktodayMITA45Claude Code, Codex
market-gap-analysisnexscope-ai/eCommerce-SkillsSkill1.6ktodayMITA38Claude Code, Codex