c-string-and-buffer-safety
Installation
SKILL.md
C String & Buffer Safety
When to use
- Writing C that copies user-controlled or variable-length strings into fixed buffers.
- Reviewing code that uses
strncpy,snprintf,strcpy,strcat,sprintf,gets,memcpy,memset. - Checking whether a buffer is large enough for what is copied into it.
- Reasoning about truncation: does the call report when the output was cut off?
- Porting code between BSD (strlcpy/strscpy), Linux kernel, and standard C11 environments.
When not to use
- Pure C++ code with
std::string/std::vector— seeraii-descriptor-types-api-design. - Rust — ownership + bounds checks are compile-time; use
rust-unsafe-reasoningfor unsafe blocks. - When the concern is a specific UB construct rather than string copying, route through
c-undefined-behavior. - Memory allocation correctness (leaks, double-free) — that is memory ownership, not buffer sizing.