🤖
C
Avoid common C mistakes — memory leaks, buffer overflows, undefined behavior, and pointer traps.
安全通过
技能说明
name: C slug: c version: 1.0.1 description: Write safe C avoiding memory corruption, buffer overflows, and undefined behavior traps. metadata: {"clawdbot":{"emoji":"⚙️","requires":{"bins":["gcc","clang"]},"os":["linux","darwin","win32"]}}
Quick Reference
| Topic | File |
|---|---|
| malloc/free, leaks, double free | memory.md |
| Null, dangling, pointer arithmetic | pointers.md |
| Null terminator, buffer overflow | strings.md |
| Integer overflow, signed/unsigned | types.md |
| Macro traps, include guards | preprocessor.md |
| Common undefined behavior | undefined.md |
Critical Rules
mallocreturnsvoid*— cast required in C++, optional in C but check for NULLfree(ptr); ptr = NULL;— always null after free to prevent double-freesizeof(array)in function gives pointer size, not array size — pass length separatelychar str[5] = "hello";— no room for null terminator, UB when used as stringstrcpydoesn't check bounds — usestrncpyand manually null-terminate- Signed overflow is UB — compiler can optimize assuming it never happens
i++ + i++is UB — no sequence point between modifications- Returning pointer to local variable — dangling pointer, UB on use
#define SQUARE(x) x*x—SQUARE(1+2)=1+2*1+2= 5, not 9memcpywith overlapping regions — usememmoveinstead- Uninitialized variables — contain garbage, UB if used
- Array out of bounds — no runtime check, silent corruption or crash
如何使用「C」?
- 打开小龙虾AI(Web 或 iOS App)
- 点击上方「立即使用」按钮,或在对话框中输入任务描述
- 小龙虾AI 会自动匹配并调用「C」技能完成任务
- 结果即时呈现,支持继续对话优化