@mytechtoday/augment-extensions 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
- package/augment-extensions/coding-standards/c/LICENSE +22 -0
- package/augment-extensions/coding-standards/c/README.md +167 -0
- package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
- package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
- package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
- package/augment-extensions/coding-standards/c/config/schema.json +244 -0
- package/augment-extensions/coding-standards/c/docs/API.md +613 -0
- package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
- package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
- package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
- package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
- package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
- package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
- package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
- package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
- package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
- package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
- package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
- package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
- package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
- package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
- package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
- package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
- package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
- package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
- package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
- package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
- package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
- package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
- package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
- package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
- package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
- package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
- package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
- package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
- package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
- package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
- package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
- package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
- package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
- package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
- package/augment-extensions/coding-standards/c/module.json +149 -0
- package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
- package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
- package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
- package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
- package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
- package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
- package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
- package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
- package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
- package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
- package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
- package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
- package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
- package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
- package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
- package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
- package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
- package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
- package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
- package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
- package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
- package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
- package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
- package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
- package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
- package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
- package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
- package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
- package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
- package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
- package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
- package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
- package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
- package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
- package/augment-extensions/coding-standards/go/README.md +200 -0
- package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
- package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
- package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
- package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
- package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
- package/augment-extensions/coding-standards/go/config/schema.json +110 -0
- package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
- package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
- package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
- package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
- package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
- package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
- package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
- package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
- package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
- package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
- package/augment-extensions/coding-standards/go/module.json +139 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
- package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
- package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
- package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
- package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
- package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
- package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
- package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
- package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
- package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
- package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
- package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
- package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
- package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
- package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
- package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
- package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
- package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
- package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
- package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
- package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
- package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
- package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
- package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
- package/cli/dist/analysis/ast-parser.d.ts +47 -0
- package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
- package/cli/dist/analysis/ast-parser.js +161 -0
- package/cli/dist/analysis/ast-parser.js.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.js +189 -0
- package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.js +237 -0
- package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
- package/cli/dist/analysis/index.d.ts +9 -0
- package/cli/dist/analysis/index.d.ts.map +1 -0
- package/cli/dist/analysis/index.js +25 -0
- package/cli/dist/analysis/index.js.map +1 -0
- package/cli/dist/analysis/security-scanner.d.ts +11 -0
- package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
- package/cli/dist/analysis/security-scanner.js +294 -0
- package/cli/dist/analysis/security-scanner.js.map +1 -0
- package/cli/dist/analysis/types.d.ts +151 -0
- package/cli/dist/analysis/types.d.ts.map +1 -0
- package/cli/dist/analysis/types.js +6 -0
- package/cli/dist/analysis/types.js.map +1 -0
- package/cli/dist/cli.js +24 -0
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/code-analysis.d.ts +11 -0
- package/cli/dist/commands/code-analysis.d.ts.map +1 -0
- package/cli/dist/commands/code-analysis.js +412 -0
- package/cli/dist/commands/code-analysis.js.map +1 -0
- package/modules.md +99 -3
- package/package.json +14 -2
- package/cli/dist/commands/agent.d.ts +0 -37
- package/cli/dist/commands/agent.d.ts.map +0 -1
- package/cli/dist/commands/agent.js +0 -222
- package/cli/dist/commands/agent.js.map +0 -1
- package/cli/dist/commands/beads.d.ts +0 -64
- package/cli/dist/commands/beads.d.ts.map +0 -1
- package/cli/dist/commands/beads.js +0 -377
- package/cli/dist/commands/beads.js.map +0 -1
- package/cli/dist/commands/change.d.ts +0 -54
- package/cli/dist/commands/change.d.ts.map +0 -1
- package/cli/dist/commands/change.js +0 -243
- package/cli/dist/commands/change.js.map +0 -1
- package/cli/dist/commands/clean.d.ts +0 -15
- package/cli/dist/commands/clean.d.ts.map +0 -1
- package/cli/dist/commands/clean.js +0 -63
- package/cli/dist/commands/clean.js.map +0 -1
- package/cli/dist/commands/clone.d.ts +0 -15
- package/cli/dist/commands/clone.d.ts.map +0 -1
- package/cli/dist/commands/clone.js +0 -49
- package/cli/dist/commands/clone.js.map +0 -1
- package/cli/dist/commands/config.d.ts +0 -33
- package/cli/dist/commands/config.d.ts.map +0 -1
- package/cli/dist/commands/config.js +0 -166
- package/cli/dist/commands/config.js.map +0 -1
- package/cli/dist/commands/context.d.ts +0 -38
- package/cli/dist/commands/context.d.ts.map +0 -1
- package/cli/dist/commands/context.js +0 -205
- package/cli/dist/commands/context.js.map +0 -1
- package/cli/dist/commands/create.d.ts +0 -18
- package/cli/dist/commands/create.d.ts.map +0 -1
- package/cli/dist/commands/create.js +0 -178
- package/cli/dist/commands/create.js.map +0 -1
- package/cli/dist/commands/diff.d.ts +0 -19
- package/cli/dist/commands/diff.d.ts.map +0 -1
- package/cli/dist/commands/diff.js +0 -104
- package/cli/dist/commands/diff.js.map +0 -1
- package/cli/dist/commands/doctor.d.ts +0 -14
- package/cli/dist/commands/doctor.d.ts.map +0 -1
- package/cli/dist/commands/doctor.js +0 -62
- package/cli/dist/commands/doctor.js.map +0 -1
- package/cli/dist/commands/export.d.ts +0 -28
- package/cli/dist/commands/export.d.ts.map +0 -1
- package/cli/dist/commands/export.js +0 -135
- package/cli/dist/commands/export.js.map +0 -1
- package/cli/dist/commands/import.d.ts +0 -23
- package/cli/dist/commands/import.d.ts.map +0 -1
- package/cli/dist/commands/import.js +0 -118
- package/cli/dist/commands/import.js.map +0 -1
- package/cli/dist/commands/prompt.d.ts +0 -45
- package/cli/dist/commands/prompt.d.ts.map +0 -1
- package/cli/dist/commands/prompt.js +0 -223
- package/cli/dist/commands/prompt.js.map +0 -1
- package/cli/dist/commands/spec.d.ts +0 -57
- package/cli/dist/commands/spec.d.ts.map +0 -1
- package/cli/dist/commands/spec.js +0 -279
- package/cli/dist/commands/spec.js.map +0 -1
- package/cli/dist/commands/stats.d.ts +0 -18
- package/cli/dist/commands/stats.d.ts.map +0 -1
- package/cli/dist/commands/stats.js +0 -85
- package/cli/dist/commands/stats.js.map +0 -1
- package/cli/dist/commands/task.d.ts +0 -65
- package/cli/dist/commands/task.d.ts.map +0 -1
- package/cli/dist/commands/task.js +0 -282
- package/cli/dist/commands/task.js.map +0 -1
- package/cli/dist/commands/template.d.ts +0 -17
- package/cli/dist/commands/template.d.ts.map +0 -1
- package/cli/dist/commands/template.js +0 -55
- package/cli/dist/commands/template.js.map +0 -1
- package/cli/dist/utils/agent-config.d.ts +0 -129
- package/cli/dist/utils/agent-config.d.ts.map +0 -1
- package/cli/dist/utils/agent-config.js +0 -297
- package/cli/dist/utils/agent-config.js.map +0 -1
- package/cli/dist/utils/beads-graph.d.ts +0 -17
- package/cli/dist/utils/beads-graph.d.ts.map +0 -1
- package/cli/dist/utils/beads-graph.js +0 -150
- package/cli/dist/utils/beads-graph.js.map +0 -1
- package/cli/dist/utils/beads-integration.d.ts +0 -112
- package/cli/dist/utils/beads-integration.d.ts.map +0 -1
- package/cli/dist/utils/beads-integration.js +0 -312
- package/cli/dist/utils/beads-integration.js.map +0 -1
- package/cli/dist/utils/beads-reporter.d.ts +0 -17
- package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
- package/cli/dist/utils/beads-reporter.js +0 -160
- package/cli/dist/utils/beads-reporter.js.map +0 -1
- package/cli/dist/utils/cache-manager.d.ts +0 -55
- package/cli/dist/utils/cache-manager.d.ts.map +0 -1
- package/cli/dist/utils/cache-manager.js +0 -150
- package/cli/dist/utils/cache-manager.js.map +0 -1
- package/cli/dist/utils/change-manager.d.ts +0 -70
- package/cli/dist/utils/change-manager.d.ts.map +0 -1
- package/cli/dist/utils/change-manager.js +0 -412
- package/cli/dist/utils/change-manager.js.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
- package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.js +0 -77
- package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
- package/cli/dist/utils/context-manager.d.ts +0 -96
- package/cli/dist/utils/context-manager.d.ts.map +0 -1
- package/cli/dist/utils/context-manager.js +0 -258
- package/cli/dist/utils/context-manager.js.map +0 -1
- package/cli/dist/utils/diff-engine.d.ts +0 -78
- package/cli/dist/utils/diff-engine.d.ts.map +0 -1
- package/cli/dist/utils/diff-engine.js +0 -233
- package/cli/dist/utils/diff-engine.js.map +0 -1
- package/cli/dist/utils/export-system.d.ts +0 -101
- package/cli/dist/utils/export-system.d.ts.map +0 -1
- package/cli/dist/utils/export-system.js +0 -289
- package/cli/dist/utils/export-system.js.map +0 -1
- package/cli/dist/utils/health-checker.d.ts +0 -66
- package/cli/dist/utils/health-checker.d.ts.map +0 -1
- package/cli/dist/utils/health-checker.js +0 -285
- package/cli/dist/utils/health-checker.js.map +0 -1
- package/cli/dist/utils/import-system.d.ts +0 -74
- package/cli/dist/utils/import-system.d.ts.map +0 -1
- package/cli/dist/utils/import-system.js +0 -317
- package/cli/dist/utils/import-system.js.map +0 -1
- package/cli/dist/utils/module-cloner.d.ts +0 -40
- package/cli/dist/utils/module-cloner.d.ts.map +0 -1
- package/cli/dist/utils/module-cloner.js +0 -136
- package/cli/dist/utils/module-cloner.js.map +0 -1
- package/cli/dist/utils/prompt-manager.d.ts +0 -90
- package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
- package/cli/dist/utils/prompt-manager.js +0 -302
- package/cli/dist/utils/prompt-manager.js.map +0 -1
- package/cli/dist/utils/spec-manager.d.ts +0 -65
- package/cli/dist/utils/spec-manager.d.ts.map +0 -1
- package/cli/dist/utils/spec-manager.js +0 -329
- package/cli/dist/utils/spec-manager.js.map +0 -1
- package/cli/dist/utils/stats-collector.d.ts +0 -74
- package/cli/dist/utils/stats-collector.d.ts.map +0 -1
- package/cli/dist/utils/stats-collector.js +0 -164
- package/cli/dist/utils/stats-collector.js.map +0 -1
- package/cli/dist/utils/template-engine.d.ts +0 -47
- package/cli/dist/utils/template-engine.d.ts.map +0 -1
- package/cli/dist/utils/template-engine.js +0 -204
- package/cli/dist/utils/template-engine.js.map +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Rule: Memory Safety
|
|
2
|
+
|
|
3
|
+
## Metadata
|
|
4
|
+
- **ID**: universal-memory-safety
|
|
5
|
+
- **Category**: universal
|
|
6
|
+
- **Severity**: ERROR
|
|
7
|
+
- **Standard**: CERT C, MISRA C
|
|
8
|
+
- **Version**: 1.0.0
|
|
9
|
+
|
|
10
|
+
## Description
|
|
11
|
+
Ensure proper memory management through correct allocation/deallocation pairing, bounds checking, null pointer validation, and use-after-free prevention.
|
|
12
|
+
|
|
13
|
+
## Rationale
|
|
14
|
+
Memory safety violations are the leading cause of security vulnerabilities and crashes in C programs. Proper memory management prevents buffer overflows, memory leaks, use-after-free bugs, and null pointer dereferences.
|
|
15
|
+
|
|
16
|
+
## Applies To
|
|
17
|
+
- C Standards: c89, c99, c11, c17, c23
|
|
18
|
+
- Categories: all
|
|
19
|
+
|
|
20
|
+
## Rule Details
|
|
21
|
+
|
|
22
|
+
### 1. Allocation and Deallocation Pairing
|
|
23
|
+
- Every `malloc()`, `calloc()`, `realloc()` must have a corresponding `free()`
|
|
24
|
+
- Set pointers to NULL after freeing
|
|
25
|
+
- Use RAII-like patterns with cleanup functions
|
|
26
|
+
|
|
27
|
+
### 2. Bounds Checking
|
|
28
|
+
- Always validate array indices before access
|
|
29
|
+
- Use `sizeof()` for buffer size calculations
|
|
30
|
+
- Prefer safe string functions (`strncpy`, `snprintf`)
|
|
31
|
+
|
|
32
|
+
### 3. Null Pointer Validation
|
|
33
|
+
- Check return values from allocation functions
|
|
34
|
+
- Validate pointers before dereferencing
|
|
35
|
+
- Handle allocation failures gracefully
|
|
36
|
+
|
|
37
|
+
### 4. Use-After-Free Prevention
|
|
38
|
+
- Set pointers to NULL after freeing
|
|
39
|
+
- Avoid dangling pointers
|
|
40
|
+
- Use ownership patterns to clarify lifetime
|
|
41
|
+
|
|
42
|
+
## Examples
|
|
43
|
+
|
|
44
|
+
### ✅ Good Example 1: Proper Allocation and Deallocation
|
|
45
|
+
|
|
46
|
+
```c
|
|
47
|
+
#include <stdlib.h>
|
|
48
|
+
#include <string.h>
|
|
49
|
+
|
|
50
|
+
char* create_user_name(const char* first, const char* last) {
|
|
51
|
+
if (first == NULL || last == NULL) {
|
|
52
|
+
return NULL;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
size_t len = strlen(first) + strlen(last) + 2; // +1 for space, +1 for null
|
|
56
|
+
char* full_name = malloc(len);
|
|
57
|
+
|
|
58
|
+
if (full_name == NULL) {
|
|
59
|
+
return NULL; // Allocation failed
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
snprintf(full_name, len, "%s %s", first, last);
|
|
63
|
+
return full_name;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void process_user(void) {
|
|
67
|
+
char* name = create_user_name("John", "Doe");
|
|
68
|
+
|
|
69
|
+
if (name != NULL) {
|
|
70
|
+
printf("User: %s\n", name);
|
|
71
|
+
free(name);
|
|
72
|
+
name = NULL; // Prevent use-after-free
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### ✅ Good Example 2: Bounds Checking
|
|
78
|
+
|
|
79
|
+
```c
|
|
80
|
+
#include <string.h>
|
|
81
|
+
|
|
82
|
+
#define MAX_BUFFER 256
|
|
83
|
+
|
|
84
|
+
int safe_copy(char* dest, const char* src, size_t dest_size) {
|
|
85
|
+
if (dest == NULL || src == NULL || dest_size == 0) {
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
size_t src_len = strlen(src);
|
|
90
|
+
if (src_len >= dest_size) {
|
|
91
|
+
return -1; // Source too large
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
strncpy(dest, src, dest_size - 1);
|
|
95
|
+
dest[dest_size - 1] = '\0'; // Ensure null termination
|
|
96
|
+
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### ✅ Good Example 3: Array Bounds Validation
|
|
102
|
+
|
|
103
|
+
```c
|
|
104
|
+
#define ARRAY_SIZE 100
|
|
105
|
+
|
|
106
|
+
int get_element(const int* array, size_t array_len, size_t index, int* out) {
|
|
107
|
+
if (array == NULL || out == NULL) {
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (index >= array_len) {
|
|
112
|
+
return -1; // Out of bounds
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
*out = array[index];
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### ✅ Good Example 4: Cleanup Pattern
|
|
121
|
+
|
|
122
|
+
```c
|
|
123
|
+
typedef struct {
|
|
124
|
+
char* name;
|
|
125
|
+
int* data;
|
|
126
|
+
size_t data_len;
|
|
127
|
+
} Resource;
|
|
128
|
+
|
|
129
|
+
Resource* resource_create(const char* name, size_t data_len) {
|
|
130
|
+
Resource* res = calloc(1, sizeof(Resource));
|
|
131
|
+
if (res == NULL) {
|
|
132
|
+
return NULL;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
res->name = strdup(name);
|
|
136
|
+
if (res->name == NULL) {
|
|
137
|
+
free(res);
|
|
138
|
+
return NULL;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
res->data = calloc(data_len, sizeof(int));
|
|
142
|
+
if (res->data == NULL) {
|
|
143
|
+
free(res->name);
|
|
144
|
+
free(res);
|
|
145
|
+
return NULL;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
res->data_len = data_len;
|
|
149
|
+
return res;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
void resource_destroy(Resource** res) {
|
|
153
|
+
if (res == NULL || *res == NULL) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
free((*res)->name);
|
|
158
|
+
free((*res)->data);
|
|
159
|
+
free(*res);
|
|
160
|
+
*res = NULL; // Prevent use-after-free
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### ❌ Bad Example 1: Memory Leak
|
|
165
|
+
|
|
166
|
+
```c
|
|
167
|
+
void process_data(void) {
|
|
168
|
+
char* buffer = malloc(1024);
|
|
169
|
+
// ... use buffer ...
|
|
170
|
+
// Missing free() - memory leak!
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### ❌ Bad Example 2: Use-After-Free
|
|
175
|
+
|
|
176
|
+
```c
|
|
177
|
+
void dangerous_code(void) {
|
|
178
|
+
int* data = malloc(sizeof(int) * 10);
|
|
179
|
+
free(data);
|
|
180
|
+
data[0] = 42; // Use-after-free!
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### ❌ Bad Example 3: Buffer Overflow
|
|
185
|
+
|
|
186
|
+
```c
|
|
187
|
+
void unsafe_copy(char* dest) {
|
|
188
|
+
char* src = "This is a very long string that will overflow";
|
|
189
|
+
strcpy(dest, src); // No bounds checking!
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### ❌ Bad Example 4: Null Pointer Dereference
|
|
194
|
+
|
|
195
|
+
```c
|
|
196
|
+
void crash_prone(void) {
|
|
197
|
+
int* ptr = malloc(sizeof(int));
|
|
198
|
+
// No null check!
|
|
199
|
+
*ptr = 42; // Crash if malloc failed
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Static Analysis Tools
|
|
204
|
+
|
|
205
|
+
### Valgrind
|
|
206
|
+
```bash
|
|
207
|
+
valgrind --leak-check=full --show-leak-kinds=all ./program
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### AddressSanitizer (ASan)
|
|
211
|
+
```bash
|
|
212
|
+
gcc -fsanitize=address -g program.c -o program
|
|
213
|
+
./program
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Clang Static Analyzer
|
|
217
|
+
```bash
|
|
218
|
+
clang --analyze program.c
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## References
|
|
222
|
+
|
|
223
|
+
- [CERT C - MEM30-C](https://wiki.sei.cmu.edu/confluence/display/c/MEM30-C.+Do+not+access+freed+memory)
|
|
224
|
+
- [CERT C - MEM31-C](https://wiki.sei.cmu.edu/confluence/display/c/MEM31-C.+Free+dynamically+allocated+memory+when+no+longer+needed)
|
|
225
|
+
- [MISRA C:2012 Rule 22.1](https://www.misra.org.uk/)
|
|
226
|
+
- [CWE-119: Buffer Overflow](https://cwe.mitre.org/data/definitions/119.html)
|
|
227
|
+
- [CWE-416: Use After Free](https://cwe.mitre.org/data/definitions/416.html)
|
|
228
|
+
|
|
229
|
+
## Related Rules
|
|
230
|
+
|
|
231
|
+
- `universal-error-handling` - Check allocation return values
|
|
232
|
+
- `category-embedded` - No dynamic allocation in embedded systems
|
|
233
|
+
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Rule: Naming Conventions
|
|
2
|
+
|
|
3
|
+
## Metadata
|
|
4
|
+
- **ID**: universal-naming
|
|
5
|
+
- **Category**: universal
|
|
6
|
+
- **Severity**: WARNING
|
|
7
|
+
- **Standard**: Linux Kernel Style, GNU Coding Standards
|
|
8
|
+
- **Version**: 1.0.0
|
|
9
|
+
|
|
10
|
+
## Description
|
|
11
|
+
Use consistent naming conventions: snake_case for functions and variables, UPPER_CASE for macros and constants, PascalCase for types.
|
|
12
|
+
|
|
13
|
+
## Rationale
|
|
14
|
+
Consistent naming improves code readability and maintainability. It helps distinguish between different types of identifiers at a glance, reducing cognitive load and preventing errors.
|
|
15
|
+
|
|
16
|
+
## Applies To
|
|
17
|
+
- C Standards: c89, c99, c11, c17, c23
|
|
18
|
+
- Categories: all
|
|
19
|
+
|
|
20
|
+
## Rule Details
|
|
21
|
+
|
|
22
|
+
### Functions and Variables
|
|
23
|
+
Use `snake_case` for function names and variable names:
|
|
24
|
+
- All lowercase letters
|
|
25
|
+
- Words separated by underscores
|
|
26
|
+
- Descriptive names that convey purpose
|
|
27
|
+
|
|
28
|
+
### Macros and Constants
|
|
29
|
+
Use `UPPER_CASE` for preprocessor macros and constants:
|
|
30
|
+
- All uppercase letters
|
|
31
|
+
- Words separated by underscores
|
|
32
|
+
- Prefix with module name to avoid collisions
|
|
33
|
+
|
|
34
|
+
### Types
|
|
35
|
+
Use `PascalCase` or `snake_case_t` suffix for type definitions:
|
|
36
|
+
- Struct/union/enum names: PascalCase or snake_case
|
|
37
|
+
- Typedef names: snake_case with `_t` suffix
|
|
38
|
+
- Enum constants: UPPER_CASE
|
|
39
|
+
|
|
40
|
+
## Examples
|
|
41
|
+
|
|
42
|
+
### ✅ Good Examples
|
|
43
|
+
|
|
44
|
+
```c
|
|
45
|
+
// Functions - snake_case
|
|
46
|
+
int calculate_total_price(int quantity, double unit_price);
|
|
47
|
+
void initialize_network_connection(void);
|
|
48
|
+
char* get_user_name(int user_id);
|
|
49
|
+
|
|
50
|
+
// Variables - snake_case
|
|
51
|
+
int user_count = 0;
|
|
52
|
+
double average_temperature = 0.0;
|
|
53
|
+
char* file_path = NULL;
|
|
54
|
+
|
|
55
|
+
// Macros - UPPER_CASE
|
|
56
|
+
#define MAX_BUFFER_SIZE 1024
|
|
57
|
+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
58
|
+
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
|
59
|
+
|
|
60
|
+
// Constants - UPPER_CASE
|
|
61
|
+
const int MAX_CONNECTIONS = 100;
|
|
62
|
+
const double PI = 3.14159265359;
|
|
63
|
+
|
|
64
|
+
// Types - PascalCase or snake_case_t
|
|
65
|
+
typedef struct {
|
|
66
|
+
int id;
|
|
67
|
+
char name[64];
|
|
68
|
+
} User;
|
|
69
|
+
|
|
70
|
+
typedef struct connection_info {
|
|
71
|
+
int socket_fd;
|
|
72
|
+
char ip_address[16];
|
|
73
|
+
} connection_info_t;
|
|
74
|
+
|
|
75
|
+
// Enums
|
|
76
|
+
typedef enum {
|
|
77
|
+
STATUS_SUCCESS,
|
|
78
|
+
STATUS_ERROR,
|
|
79
|
+
STATUS_PENDING
|
|
80
|
+
} Status;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### ❌ Bad Examples
|
|
84
|
+
|
|
85
|
+
```c
|
|
86
|
+
// Inconsistent function naming
|
|
87
|
+
int CalculateTotalPrice(int qty, double price); // PascalCase - wrong
|
|
88
|
+
void InitNetConn(void); // Abbreviated - unclear
|
|
89
|
+
char* GetUserName(int ID); // Mixed case - wrong
|
|
90
|
+
|
|
91
|
+
// Inconsistent variable naming
|
|
92
|
+
int UserCount = 0; // PascalCase - wrong
|
|
93
|
+
double avgTemp = 0.0; // camelCase - wrong
|
|
94
|
+
char* FilePath = NULL; // PascalCase - wrong
|
|
95
|
+
|
|
96
|
+
// Lowercase macros
|
|
97
|
+
#define max_buffer_size 1024 // lowercase - wrong
|
|
98
|
+
#define min(a, b) ((a) < (b) ? (a) : (b)) // lowercase - wrong
|
|
99
|
+
|
|
100
|
+
// Inconsistent type naming
|
|
101
|
+
typedef struct {
|
|
102
|
+
int id;
|
|
103
|
+
char name[64];
|
|
104
|
+
} user; // lowercase - unclear
|
|
105
|
+
|
|
106
|
+
typedef struct ConnectionInfo {
|
|
107
|
+
int socketFd; // camelCase - wrong
|
|
108
|
+
char IPAddress[16]; // Mixed case - wrong
|
|
109
|
+
} ConnectionInfo;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 🔧 Refactoring Example
|
|
113
|
+
|
|
114
|
+
**Before:**
|
|
115
|
+
```c
|
|
116
|
+
#define maxSize 100
|
|
117
|
+
int GetUserAge(int UserID);
|
|
118
|
+
typedef struct { int x; int y; } point;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**After:**
|
|
122
|
+
```c
|
|
123
|
+
#define MAX_SIZE 100
|
|
124
|
+
int get_user_age(int user_id);
|
|
125
|
+
typedef struct { int x; int y; } Point;
|
|
126
|
+
// or
|
|
127
|
+
typedef struct { int x; int y; } point_t;
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Exceptions
|
|
131
|
+
|
|
132
|
+
1. **Platform-specific code**: May follow platform conventions (e.g., Windows API uses PascalCase)
|
|
133
|
+
2. **Third-party integration**: May match external library naming for consistency
|
|
134
|
+
3. **Legacy code**: Gradual migration preferred over immediate breaking changes
|
|
135
|
+
|
|
136
|
+
## References
|
|
137
|
+
|
|
138
|
+
- [Linux Kernel Coding Style](https://www.kernel.org/doc/html/latest/process/coding-style.html)
|
|
139
|
+
- [GNU Coding Standards](https://www.gnu.org/prep/standards/standards.html)
|
|
140
|
+
- [CERT C Coding Standard - DCL04-C](https://wiki.sei.cmu.edu/confluence/display/c/DCL04-C.+Do+not+declare+more+than+one+variable+per+declaration)
|
|
141
|
+
|
|
142
|
+
## Related Rules
|
|
143
|
+
|
|
144
|
+
- `universal-documentation` - Naming should align with documentation
|
|
145
|
+
- `universal-const-correctness` - Constant naming conventions
|
|
146
|
+
|