c-advanced

c-advanced is a cursor rule for Cursor from wangqiqi/cursor-ai-rules. It costs 0 tokens per session (2,940 once invoked), scanned A, original, MIT.

Advanced guidance for C programming covering testing, performance improvements, security, memory and resource handling, and general development practices. C is a low-level programming language where incorrect memory use can cause crashes or security flaws.

In plain words
What is it for?
Use it when developing or reviewing C code that needs safer memory handling, compiler optimizations, static analysis, performance testing, or cross-platform checks.
Why use it?
It helps prevent common C problems such as buffer overflows, unsafe functions, memory mistakes, portability issues, and untested performance changes.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when developing or reviewing C code that needs safer memory handling, compiler optimizations, static analysis, performance testing, or cross-platform checks.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/wangqiqi/cursor-ai-rules/c-advanced
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/wangqiqi/cursor-ai-rules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for c-advanced

README.md
[![agentmods](https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/c-advanced/github.svg)](https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/c-advanced)
Your own site
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/c-advanced"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/c-advanced/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for c-advanced

Your own site · 80×15
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/c-advanced"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/c-advanced.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,940 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.02940
Opus 5.5 $0.00000 $0.01176
Sonnet 5.5 $0.00000 $0.00588
Haiku 4.5 $0.00000 $0.00294

Measured 3mo ago against content hash 66ea80c40451, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

c-advanced scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tech/c-advanced.mdc · 447 lines

How it starts

The opening of the file, as written. The whole thing — 447 lines — stays where its author put it; the contents beside it link to each section on GitHub.

C 高级实践

本文档是从 @c-basics 分割出来的高级主题部分,涵盖测试策略、性能优化、安全实践和最佳实践。

⚠️ 执行原则

MUST 遵循以下C高级开发准则:

  • MUST 正确管理内存和资源
  • NEVER 忽略缓冲区溢出风险
  • ALWAYS 使用静态分析工具
  • DO NOT 使用不安全的函数
  • MUST 进行性能测试和优化
  • ALWAYS 验证跨平台兼容性

编译优化

// 条件编译优化
#ifdef __GNUC__
#define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#endif

// 内联函数优化
static inline int fast_max(int a, int b) {
    return LIKELY(a > b) ? a : b;
}

// 分支预测优化
int process_data_optimized(const int* data, size_t count) {
    int sum = 0;
    for (size_t i = 0; i < count; ++i) {
        if (LIKELY(data[i] > 0)) { // 正数更常见
            sum += data[i];
        } else {
            sum -= data[i]; // 负数处理
        }
    }
    return sum;
}

// SIMD优化 (需要编译器支持)
#ifdef __AVX2__
#include <immintrin.h>

void vector_add_float(float* result, const float* a, const float* b, size_t count) {
    size_t i = 0;

    // SIMD处理
    for (; i + 8 <= count; i += 8) {
        __m256 va = _mm256_load_ps(&a[i]);
        __m256 vb = _mm256_load_ps(&b[i]);
        __m256 vr = _mm256_add_ps(va, vb);
        _mm256_store_ps(&result[i], vr);
    }

    // 处理剩余元素
    for (; i < count; ++i) {
        result[i] = a[i] + b[i];
    }
}

#else

void vector_add_float(float* result, const float* a, const float* b, size_t count) {
    for (size_t i = 0; i < count; ++i) {
        result[i] = a[i] + b[i];
    }
}

#endif

🔒 安全实践

缓冲区溢出防护

#include <string.h>
#include <stdio.h>

// ✅ 推荐:安全的字符串操作
size_t safe_strncpy(char* dest, const char* src, size_t dest_size) {
    if (!dest || !src || dest_size == 0) {
        return 0;
    }

    size_t src_len = strnlen(src, dest_size);
    if (src_len < dest_size) {
        // 源字符串完全适合
        memcpy(dest, src, src_len);
        dest[src_len] = '\0';
        return src_len;
    } else {
        // 需要截断
        memcpy(dest, src, dest_size - 1);
        dest[dest_size - 1] = '\0';
        return dest_size - 1;
    }
}

size_t safe_strncat(char* dest, const char* src, size_t dest_size) {
    if (!dest || !src || dest_size == 0) {
        return 0;
    }

    size_t dest_len = strnlen(dest, dest_size);
    if (dest_len >= dest_size) {
        return 0; // 目标缓冲区已满或无效
    }

    size_t remaining = dest_size - dest_len;
    size_t src_len = strnlen(src, remaining);

    memcpy(dest + dest_len, src, src_len);
    dest[dest_len + src_len] = '\0';

    return src_len;
}

// ✅ 推荐:安全的内存操作
void* safe_memcpy(void* dest, const void* src, size_t count) {
    if (!dest || !src) {
        return NULL;
    }

    // 检查重叠
    if ((char*)dest < (char*)src + count &&
        (char*)src < (char*)dest + count) {
        // 重叠,使用memmove
        return memmove(dest, src, count);
    }

    return memcpy(dest, src, count);
}

void* safe_malloc(size_t size) {
    if (size == 0) {
        size = 1; // 避免分配0字节
    }

    if (size > SIZE_MAX / 2) {
        return NULL; // 防止整数溢出
    }

    return malloc(size);
}

Read the full file on GitHub · 447 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 447 lines · 0 tokens per session scan A 66ea80c40451

Subscribe to this mod's changes

c-advanced is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (16 stars, last pushed 6mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,940 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

c-advanced compared with cursor rules from other repositories

c-advanced next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
c-advancedwangqiqi/cursor-ai-rulesCursor rule166mo agoMITA0Cursor
djangosanjeed5/awesome-cursor-rules-mdcCursor rule3.6k8d agoCC0-1.0A2,043Cursor
richsanjeed5/awesome-cursor-rules-mdcCursor rule3.6k8d agoCC0-1.0A1,749Cursor
pythonPatrickJS/awesome-cursorrulesCursor rule41k6mo agoCC0-1.0A734Cursor
gosupertokens/create-supertokens-appCursor rule245d agoApache-2.0A0Cursor
fastapi-rulesbeel-collab/presets.devCursor rule38d agoMITA0Cursor
shared-librarieskubev2v/forklift-console-pluginCursor rule11todayApache-2.0A16Cursor