/ct:c-languagefrom ct
Diagnoses undefined behavior, configures sanitizers (ASan/UBSan/TSan/MSan), hardening flags, atomics/memory ordering, fuzzing, and ABI quirks in C. Loads when UB, sanitizers, data races, or alignment/atomics are discussed.
Ships in ct. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Concise pointers for C undefined-behavior diagnosis, sanitizer/fuzzer workflows, and hardened builds.
Assumes you already know pointers, structs, malloc/free, and basic stdio. This skill covers the operational layer — the parts models gloss over: UB landmines that compilers weaponize, sanitizer combinations and their costs, hardening flag stacks, and ABI/alignment quirks.
Load when the question is about:
_FORTIFY_SOURCE, RELRO, CFI, PIE)volatile is and isn't validDo NOT load for: writing basic C, simple printf/scanf, struct layout walk-throughs, learning malloc/free — defaults are fine.
Compilers treat UB as assume(no UB) and delete code paths assuming the assumption held. Stating the rule: once UB happens, the entire execution is meaningless (Regehr).
INT_MAX + 1). Compiler may delete the bounds check if (x + 1 < x) abort() because the only way x+1<x is via overflow which "can't happen." Tame with -fwrapv (defines wrap as two's complement) or trap with -ftrapv. Detect at runtime via -fsanitize=signed-integer-overflow.uint16_t a = 0xFFFF; a*a promotes to int first → 0xFFFE0001 overflows signed int on 32-bit int. UB. Force unsigned: (uint32_t)a * a.x << n with n >= width(x) is UB. So is shift of negative signed value. 1 << 31 on 32-bit int is UB (sign-bit). Use 1u << 31 or (uint32_t)1 << 31.int* to float* and dereferencing is UB. Compilers use this for TBAA optimizations and will reorder writes through "incompatible" pointers.memcpy: float f; uint32_t u; memcpy(&u, &f, sizeof u); Compilers recognize this and emit zero copies at -O1+. Union punning is implementation-defined in C99 but well-defined in C11 §6.5.2.3 footnote — still avoid for portability across C++ and odd compilers. Pointer-cast punning is UB except via char*.-fno-strict-aliasing (Linux kernel ships with this), __attribute__((may_alias)) on a typedef to mark it as aliasing-permissive, or memcpy for one-off pun.int x = p->a; if (p) ... — the deref before the null check tells the compiler p is non-null, so it deletes the if. CVE-2009-1897 (Linux tun driver) was exactly this. Tame with -fno-delete-null-pointer-checks.-Wuninitialized catches some at compile time.i = i++ + 1;, a[i] = i++; are UB pre-C11 and unsequenced/UB in C11. -Wsequence-point warns.arr + n+1 (one past one past) is UB. ASan catches reads/writes; UBSan with -fsanitize=bounds catches indexing.| Sanitizer | Flag | Slowdown | Memory | Detects | Notes |
|---|---|---|---|---|---|
| ASan | -fsanitize=address | ~2x | up to 3x stack, 16+ TB virt | heap/stack/global OOB, UAF, double-free | Leak detection on Linux by default; ASAN_OPTIONS=detect_leaks=1 on macOS |
| UBSan | -fsanitize=undefined | small | minimal | signed overflow, shifts, alignment, null deref, bad enum, vptr | Pair with -fno-sanitize-recover=undefined to abort on first hit |
| TSan | -fsanitize=thread | 5–15x | 5–10x | data races, lock-order issues | 64-bit only; PIE required; cannot combine with ASan |
| MSan | -fsanitize=memory | ~3x (1.5–2x more w/ origins) | 2–3x | uninitialized reads | clang-only; needs instrumented libc++/dependencies; -fsanitize-memory-track-origins=2 |
| LeakSan | -fsanitize=leak | tiny | tiny | leaks only | Subset of ASan |
-fsanitize=address,undefined -fno-omit-frame-pointer -g -O1. Keep -O1 minimum so inlined frames remain readable but optimizations aren't disabled (some bugs only manifest under opt).kcachegrind to view).Stack these in release builds:
-O2 -D_FORTIFY_SOURCE=3 \
-fstack-protector-strong -fstack-clash-protection \
-fcf-protection=full \
-fPIE -pie \
-Wl,-z,relro,-z,now -Wl,-z,noexecstack
-D_FORTIFY_SOURCE=2: compile-time + runtime checks on str*, mem*, *printf using __builtin_object_size.-D_FORTIFY_SOURCE=3 (glibc ≥ 2.34, GCC ≥ 12): uses __builtin_dynamic_object_size — protects ~2.4x more call sites than =2 with no measured perf impact (Fedora SPEC2017 data). Default in Fedora/Arch.-fstack-protector-strong: canaries on functions with arrays or address-taken locals (better coverage than plain -fstack-protector, less overhead than -all).-fstack-clash-protection: probes each page on large allocations, defeats stack-clash (CVE-2017-1000366 class).-fcf-protection=full (x86-64): IBT/SHSTK, Intel CET — defends ROP/JOP. ARM equivalent: -mbranch-protection=standard.-fPIE -pie: enables ASLR for the executable text. Required on most modern distros.-Wl,-z,relro,-z,now: full RELRO — GOT made read-only, lazy binding disabled. Defeats GOT overwrite.-Wl,-z,noexecstack: NX bit on stack pages.-fhardened as a single switch enabling these.-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion \
-Wformat=2 -Wformat-security -Wstrict-prototypes \
-Wold-style-definition -Wmissing-prototypes -Wmissing-declarations \
-Wcast-align -Wcast-qual -Wpointer-arith -Wnull-dereference \
-Wdouble-promotion -Wfloat-equal -Wundef -Wwrite-strings \
-Werror=implicit-function-declaration -Werror=incompatible-pointer-types
-Werror=implicit-function-declaration is critical: pre-C99 implicit int declarations silently corrupt long/size_t returns on 64-bit. C23 removes implicit declarations — catch them now.-Wstrict-prototypes + -Wold-style-definition: forbid K&R f() (which means "unspecified args", not "no args" pre-C23). C23 makes f() mean f(void) — code relying on K&R semantics breaks.-Wcast-align: catches alignment-reducing casts that segfault on ARMv7/SPARC and are silently slow on x86.restrict_Alignof(T) (C11). Misaligned access is UB even on x86 where it merely tanks perf; on ARMv7 it traps. ARMv8 + Linux usually fixes up but spends µs each._Alignas(N) T x; requests alignment. For dynamic: aligned_alloc(N, size) (C11) or POSIX posix_memalign(&p, N, size). N must be a power of two and ≥ sizeof(void*).__builtin_assume_aligned(p, 16) tells the compiler p is 16-aligned — enables vectorized loads. UB if false.__attribute__((packed)) on a struct: removes padding, but member loads through &s->member are now misaligned reads — UB on strict-alignment archs unless accessed through the struct expression itself. Prefer memcpy for packed-struct field access.restrict (C99): function parameter T *restrict p is a promise by the caller that no other pointer in scope reaches the same object during p's lifetime. Lets compiler skip aliasing-pessimization (vectorize, hoist loads). Violating is UB. memcpy and strcpy use restrict — calling with overlapping ranges is UB; use memmove for overlap.<stdatomic.h> (C11). Not for "make it threadsafe" — for lock-free shared state and for breaking out of memory-ordering races. Locking already implies the right barriers.
_Atomic T x; — declare. atomic_load_explicit(&x, mo), atomic_store_explicit, atomic_fetch_add_explicit, atomic_compare_exchange_strong_explicit.memory_order_relaxed: counter increments, no ordering. Only when ordering doesn't matter.memory_order_acquire: paired with release; prevents reads after acquire from reordering before it. Used on the load side of a lock-free handoff.memory_order_release: prevents writes before release from reordering after it. Used on the store side. Pair with acquire on a matching variable.memory_order_acq_rel: for read-modify-write (CAS, fetch_add) where both sides matter.memory_order_seq_cst (default for non-_explicit ops): single total order across all threads. Most expensive — full fence on x86, dmb-ish on ARM.memory_order_consume: deprecated/effectively acquire on all real compilers.atomic_thread_fence(mo): standalone fence when you want the ordering without any specific atomic op.atomic_compare_exchange_weak may spuriously fail on LL/SC archs (ARM/PPC) — must be in a loop. _strong retries internally; use when you can't loop.volatile is NOT for threading. It only suppresses optimization on a single thread — gives no atomicity, no inter-thread ordering, no cross-CPU coherency. Use atomics. volatile is correct for: memory-mapped I/O registers, variables touched by setjmp/signal handlers (must be volatile sig_atomic_t), asm volatile to prevent dead-code elimination of side-effect asm. Linux kernel adds: I/O accessors, the jiffies legacy variable, DMA-coherent buffers.bugprone-*, cert-*, clang-analyzer-*, misc-*. Run via clang-tidy -checks='bugprone-*,cert-*,clang-analyzer-*' src/*.c -- -I include. CERT aliases redirect to the underlying check (e.g., cert-int30-c = bugprone-misplaced-widening-cast family).scan-build make — path-sensitive symbolic execution, finds null derefs, leaks, dead stores. Best for catching things UBSan misses at compile time.github/codeql-action): semantic queries; great for taint analysis and finding patterns across a repo.-fsanitize=fuzzer): in-process, coverage-guided. Define int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size). Combine with sanitizers: -fsanitize=fuzzer,address,undefined. Target must be deterministic, fast (sub-ms), tolerate malformed input, and not modify global state. No exit() in the harness.AFL_PERSISTENT), supports CmpLog and structure-aware mutators. Compile with afl-clang-lto. Pair with ASan/UBSan via AFL_USE_ASAN=1.set print pretty on, set print object on. Pretty-printers via python block in ~/.gdbinit (libstdc++/libc++ ship them; for C structs write your own). For mixed inline frames: -Og -g3 rather than -O0.rr record ./prog && rr replay — reverse-execute (reverse-cont, reverse-step) to walk backwards from a crash. Linux/x86-64 only. Indispensable for non-deterministic bugs.perf record -g ./prog && perf report for sampling profiles. perf stat -e cache-misses,cycles,instructions for HW counters.coredumpctl debug (systemd), or gdb prog core.NN. Build with -g always (strip later for distribution); -fno-omit-frame-pointer for usable stacks under sampling profilers.rdi, rsi, rdx, rcx, r8, r9, return in rax, callee-saved rbx, rbp, r12-r15. Windows x64 different: rcx, rdx, r8, r9, more callee-saved, shadow space — never assume calling conv when JIT'ing or writing inline asm.extern "C" (when used from C++) only fixes name mangling — does not normalize calling conv across OS. For ABI-stable C APIs, document layout: pin struct sizes with static_assert(sizeof(s) == N) (C11 _Static_assert).getline, strdupa, qsort_r differ or are absent on musl.pthread_* doesn't ship the same symbol versions; LD_PRELOAD interposers built against glibc may break.name_max and PATH_MAX handling stricter; some getaddrinfo corners differ.pthread_create has TLS quirks under dlopen.errno is thread-local (per _REENTRANT/__thread) but not signal-safe to read across signal handlers reliably without volatile sig_atomic_t flagging. Almost any libc call may clobber errno — capture it immediately after the call.size_t is unsigned; ssize_t (POSIX) is signed; ptrdiff_t is the result of pointer subtraction. Mixing in arithmetic with signed widths leads to surprising promotion. -Wsign-conversion flags it.time_t: 32-bit on some legacy systems → 2038 problem. Modern glibc defaults 64-bit.Compilers:
-fstack-protector*, -fcf-protection, -fhardened-fwrapv, -fno-strict-aliasing, -fno-delete-null-pointer-checksStandards & rules:
UB deep-dives:
Hardening:
Tooling:
Before recommending a non-trivial flag stack, sanitizer config, or atomics ordering:
-fsanitize=undefined, memory_order_acquire) — never paraphrase.Sanitizer output without root-cause diagnosis is worse than silence — it teaches the team to ignore alerts.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub pvillega/claude-templates --plugin ct38 skills in this plugin
/argocdDeep ArgoCD operational intuition — sync waves and hook lifecycle, ApplicationSet generators, Sync vs Health, drift root causes, sync options, AppProject constraints, rollback, multi-cluster. Load for sync ordering, hook design, drift diagnosis, generator selection, rollback planning, or multi-cluster registration. Skip for "what is GitOps", install walkthroughs, or basic Application YAML. Triggers on: "sync wave", "presync hook", "syncfail", "applicationset generator", "matrix generator", "hpa replicas drift", "ignoreDifferences", "ServerSideApply", "Replace=true", "self-heal", "app-of-apps cascade".
/audit-skillsAudit installed skills for redundancy with built-in model knowledge. Use when asked to "audit skills", "review my skills", "check skill redundancy", "which skills are useful", "clean up skills", or "are my skills teaching you anything new"./bash-hardeningDeep bash correctness — `set -euo pipefail` traps, IFS/word-splitting, trap inheritance, process substitution, array gotchas, version-gated features, ShellCheck "looks right but isn't" patterns. Load when writing or hardening non-trivial bash scripts (installers, CI, unattended ops). Skip for basic if/while/for, one-shot interactive commands, or zsh/fish/POSIX-sh work. Triggers on: "set -e not triggering", "pipefail", "trap ERR", "PIPESTATUS", "macOS bash 3.2", "shellcheck SC2086", "harden bash script", "robust bash".
/bugmagnetDiscover edge cases and test coverage gaps through systematic analysis. Use when analysing TEST coverage, hunting for edge cases, or when code-reviewer identifies test gaps. Triggers on "find holes in my tests", "what could go wrong", "is this well tested", "what edge cases am I missing". When to pick bugmagnet vs alternatives: - find-bugs → branch-diff bug scan (uses git diff, scoped to recent changes) - security-review → OWASP-categorised vulnerability audit - code-review → PR-style review with comment threads - ct:bugmagnet → test-gap edge-case discovery (THIS one) If the question is "are my TESTS missing cases?", use bugmagnet. Otherwise pick one of the three above.
/ci-failure-triageDiagnose a failing GitHub Actions run. Fetch the failing job's step logs, correlate with recent commits, and produce a ranked top-3 root-cause hypothesis plus a minimal fix proposal. Use when the user says "CI is failing", "why did the build break", "triage this GHA failure", "workflow failed", "what broke CI", or pastes a `gh run` URL / run ID. Read-only — does NOT apply fixes, restart the run, or tail logs. For workflow-file security audits use gha-security-review; for local test failures use fix-loop.
/coolifyDeep Coolify operational intuition — control-plane vs destination split, build-pack detection, env-var precedence, Traefik label generation, magic SERVICE_* variables, webhooks, preview deployments, backups, upgrade/rollback. Load when diagnosing a Coolify deployment, env-var/webhook misbehavior, Traefik label issues, multi-server destinations, or backup/restore. Skip for generic Docker/compose, generic Traefik tuning, or "what is a PaaS". Triggers on: "coolify deploy stuck", "coolify webhook", "coolify traefik labels", "SERVICE_FQDN", "coolify rollback", "Sentinel agent", "Nixpacks detection".
Other plugins' skills for the same job