重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
npx skills add https://github.com/htlin222/dotfiles --skill c-lang编写安全、高效的系统编程 C 代码。
// Always check malloc
void* ptr = malloc(size);
if (ptr == NULL) {
fprintf(stderr, "malloc failed\n");
return -1;
}
// Pair malloc with free
char* buffer = malloc(1024);
// ... use buffer ...
free(buffer);
buffer = NULL; // Prevent use-after-free
// Use calloc for zero-initialized memory
int* array = calloc(count, sizeof(int));
// Realloc safely
void* new_ptr = realloc(ptr, new_size);
if (new_ptr == NULL) {
free(ptr); // Original still valid on failure
return -1;
}
ptr = new_ptr;
// RAII-style cleanup with goto
int process_file(const char* path) {
int result = -1;
FILE* fp = NULL;
char* buffer = NULL;
fp = fopen(path, "r");
if (!fp) goto cleanup;
buffer = malloc(1024);
if (!buffer) goto cleanup;
// ... process ...
result = 0;
cleanup:
free(buffer);
if (fp) fclose(fp);
return result;
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// Linked list node
typedef struct Node {
void* data;
struct Node* next;
} Node;
// Dynamic array
typedef struct {
void** items;
size_t count;
size_t capacity;
} DynArray;
int dynarray_push(DynArray* arr, void* item) {
if (arr->count >= arr->capacity) {
size_t new_cap = arr->capacity ? arr->capacity * 2 : 8;
void** new_items = realloc(arr->items, new_cap * sizeof(void*));
if (!new_items) return -1;
arr->items = new_items;
arr->capacity = new_cap;
}
arr->items[arr->count++] = item;
return 0;
}
// Check all system calls
int fd = open(path, O_RDONLY);
if (fd == -1) {
perror("open");
return -1;
}
ssize_t n = read(fd, buf, sizeof(buf));
if (n == -1) {
perror("read");
close(fd);
return -1;
}
# Compile with debug symbols
gcc -g -Wall -Wextra -Werror -o prog prog.c
# Run with valgrind
valgrind --leak-check=full ./prog
# GDB debugging
gdb ./prog
(gdb) break main
(gdb) run
(gdb) print variable
(gdb) backtrace
const-Wall -Wextra -Werror 编译标志输入: "修复内存泄漏" 操作: 运行 valgrind,追踪分配,确保每个 malloc 都有对应的 free
输入: "优化这段 C 代码" 操作: 使用 perf 进行性能分析,识别热点,优化关键路径
每周安装次数
45
代码仓库
GitHub 星标数
75
首次出现
2026年1月22日
安全审计
安装于
codex38
opencode38
claude-code38
gemini-cli36
cursor36
github-copilot33
Write safe, efficient C code for systems programming.
// Always check malloc
void* ptr = malloc(size);
if (ptr == NULL) {
fprintf(stderr, "malloc failed\n");
return -1;
}
// Pair malloc with free
char* buffer = malloc(1024);
// ... use buffer ...
free(buffer);
buffer = NULL; // Prevent use-after-free
// Use calloc for zero-initialized memory
int* array = calloc(count, sizeof(int));
// Realloc safely
void* new_ptr = realloc(ptr, new_size);
if (new_ptr == NULL) {
free(ptr); // Original still valid on failure
return -1;
}
ptr = new_ptr;
// RAII-style cleanup with goto
int process_file(const char* path) {
int result = -1;
FILE* fp = NULL;
char* buffer = NULL;
fp = fopen(path, "r");
if (!fp) goto cleanup;
buffer = malloc(1024);
if (!buffer) goto cleanup;
// ... process ...
result = 0;
cleanup:
free(buffer);
if (fp) fclose(fp);
return result;
}
// Linked list node
typedef struct Node {
void* data;
struct Node* next;
} Node;
// Dynamic array
typedef struct {
void** items;
size_t count;
size_t capacity;
} DynArray;
int dynarray_push(DynArray* arr, void* item) {
if (arr->count >= arr->capacity) {
size_t new_cap = arr->capacity ? arr->capacity * 2 : 8;
void** new_items = realloc(arr->items, new_cap * sizeof(void*));
if (!new_items) return -1;
arr->items = new_items;
arr->capacity = new_cap;
}
arr->items[arr->count++] = item;
return 0;
}
// Check all system calls
int fd = open(path, O_RDONLY);
if (fd == -1) {
perror("open");
return -1;
}
ssize_t n = read(fd, buf, sizeof(buf));
if (n == -1) {
perror("read");
close(fd);
return -1;
}
# Compile with debug symbols
gcc -g -Wall -Wextra -Werror -o prog prog.c
# Run with valgrind
valgrind --leak-check=full ./prog
# GDB debugging
gdb ./prog
(gdb) break main
(gdb) run
(gdb) print variable
(gdb) backtrace
const where possible-Wall -Wextra -Werror flagsInput: "Fix memory leak" Action: Run valgrind, trace allocation, ensure every malloc has free
Input: "Optimize this C code" Action: Profile with perf, identify hotspots, optimize critical path
Weekly Installs
45
Repository
GitHub Stars
75
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex38
opencode38
claude-code38
gemini-cli36
cursor36
github-copilot33
Mojo GPU编程基础教程 - 无需CUDA语法的GPU计算入门
227 周安装