Skip to content
Back to skills

Unsafe Checker

ASecurity

CRITICAL: Use for unsafe Rust code review and FFI. Triggers on: unsafe, raw pointer, FFI, extern, transmute, *mut, *const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, SAFETY comment, soundness, undefined behavior, UB, safe wrapper, memory layout, bindgen, cbindgen, CString, CStr, 安全抽象, 裸指针, 外部函数接口, 内存布局, 不安全代码, FFI 绑定, 未定义行为

  • 18 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 8, 2026
documentationpythonrustnodeapiperformancedocumentation

Works with

  • api

Security analysis

A100/100

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

Scanned September 8, 2026

npx -y skills add k1-c/linear-tui --skill unsafe-checker --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Unsafe Checker?

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

Security grade badge for Unsafe Checker
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/k1-c-unsafe-checker/badge)](https://www.skillsdirectory.com/skills/k1-c-unsafe-checker)

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: unsafe-checker
description: "CRITICAL: Use for unsafe Rust code review and FFI. Triggers on: unsafe, raw pointer, FFI, extern, transmute, *mut, *const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, SAFETY comment, soundness, undefined behavior, UB, safe wrapper, memory layout, bindgen, cbindgen, CString, CStr, 安全抽象, 裸指针, 外部函数接口, 内存布局, 不安全代码, FFI 绑定, 未定义行为"
globs: ["**/*.rs"]
allowed-tools: ["Read", "Grep", "Glob"]
---

Display the following ASCII art exactly as shown. Do not modify spaces or line breaks:
```text
⚠️ **Unsafe Rust Checker Loaded**

     *  ^  *
    /◉\_~^~_/◉\
 ⚡/     o     \⚡
   '_        _'
   / '-----' \
```

---

# Unsafe Rust Checker

## When Unsafe is Valid

| Use Case | Example |
|----------|---------|
| FFI | Calling C functions |
| Low-level abstractions | Implementing `Vec`, `Arc` |
| Performance | Measured bottleneck with safe alternative too slow |

**NOT valid:** Escaping borrow checker without understanding why.

## Required Documentation

```rust
// SAFETY: <why this is safe>
unsafe { ... }

/// # Safety
/// <caller requirements>
pub unsafe fn dangerous() { ... }
```

## Quick Reference

| Operation | Safety Requirements |
|-----------|---------------------|
| `*ptr` deref | Valid, aligned, initialized |
| `&*ptr` | + No aliasing violations |
| `transmute` | Same size, valid bit pattern |
| `extern "C"` | Correct signature, ABI |
| `static mut` | Synchronization guaranteed |
| `impl Send/Sync` | Actually thread-safe |

## Common Errors

| Error | Fix |
|-------|-----|
| Null pointer deref | Check for null before deref |
| Use after free | Ensure lifetime validity |
| Data race | Add proper synchronization |
| Alignment violation | Use `#[repr(C)]`, check alignment |
| Invalid bit pattern | Use `MaybeUninit` |
| Missing SAFETY comment | Add `// SAFETY:` |

## Deprecated → Better

| Deprecated | Use Instead |
|------------|-------------|
| `mem::uninitialized()` | `MaybeUninit<T>` |
| `mem::zeroed()` for refs | `MaybeUninit<T>` |
| Raw pointer arithmetic | `NonNull<T>`, `ptr::add` |
| `CString::new().unwrap().as_ptr()` | Store `CString` first |
| `static mut` | `AtomicT` or `Mutex` |
| Manual extern | `bindgen` |

## FFI Crates

| Direction | Crate |
|-----------|-------|
| C → Rust | bindgen |
| Rust → C | cbindgen |
| Python | PyO3 |
| Node.js | napi-rs |

Claude knows unsafe Rust. Focus on SAFETY comments and soundness.

Files in this skill

  • AGENTS.md5.1 KB
  • SKILL.md2.4 KB
  • checklists/before-unsafe.md3.3 KB
  • checklists/common-pitfalls.md4.5 KB
  • checklists/review-unsafe.md3.8 KB
  • examples/ffi-patterns.md8.8 KB
  • examples/safe-abstraction.md6.9 KB
  • rules/ffi-01-no-string-direct.md2.9 KB
  • rules/ffi-02-read-ffi-docs.md3.2 KB
  • rules/ffi-03-drop-for-c-ptr.md3.6 KB
  • rules/ffi-04-panic-boundary.md3.6 KB
  • rules/ffi-05-portable-types.md2.6 KB
  • rules/ffi-06-string-abi.md3.1 KB
  • rules/ffi-07-no-drop-external.md3.2 KB
  • rules/ffi-08-error-handling.md3.5 KB
  • rules/ffi-09-ref-not-ptr.md3.1 KB
  • rules/ffi-10-thread-safety.md3.2 KB
  • rules/ffi-11-packed-ub.md3.1 KB
  • rules/ffi-12-invariant-doc.md3.9 KB
  • rules/ffi-13-data-layout.md3.1 KB

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.

Comments

Loading comments…