跳至主要内容
小龙虾小龙虾AI
🤖

C

Avoid common C mistakes — memory leaks, buffer overflows, undefined behavior, and pointer traps.

下载1.6k
星标2
版本1.0.1
AI 智能体
安全通过

技能说明


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

TopicFile
malloc/free, leaks, double freememory.md
Null, dangling, pointer arithmeticpointers.md
Null terminator, buffer overflowstrings.md
Integer overflow, signed/unsignedtypes.md
Macro traps, include guardspreprocessor.md
Common undefined behaviorundefined.md

Critical Rules

  • malloc returns void* — cast required in C++, optional in C but check for NULL
  • free(ptr); ptr = NULL; — always null after free to prevent double-free
  • sizeof(array) in function gives pointer size, not array size — pass length separately
  • char str[5] = "hello"; — no room for null terminator, UB when used as string
  • strcpy doesn't check bounds — use strncpy and 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*xSQUARE(1+2) = 1+2*1+2 = 5, not 9
  • memcpy with overlapping regions — use memmove instead
  • Uninitialized variables — contain garbage, UB if used
  • Array out of bounds — no runtime check, silent corruption or crash

如何使用「C」?

  1. 打开小龙虾AI(Web 或 iOS App)
  2. 点击上方「立即使用」按钮,或在对话框中输入任务描述
  3. 小龙虾AI 会自动匹配并调用「C技能完成任务
  4. 结果即时呈现,支持继续对话优化

相关技能