# c-snippet-revision

Adopt this skill: https://proskills.md/skills/other/jordmorr-openclaw-c-snippet-revision

Page: https://proskills.md/skills/other/jordmorr-openclaw-c-snippet-revision
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: SKILL.md
size: 5103
sha: dd9fad13fbe4b53fc0e224fa6cebac5a11dd40a4
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/SKILL.md

```text
---
name: c-snippet-revision
description: "Run a one-at-a-time C debugging and code-review revision game for interview preparation. Use when the user wants C bug-spotting practice, asks for C snippets to inspect visually, wants mixed difficulty snippet drills, or wants interactive feedback on what is wrong with a C code sample. Supports two levels: (1) short self-contained bug-spotting snippets, and (2) larger multi-function/system-style snippets with realistic ownership, API-contract, error-path, and boundary bugs."
---

# C Snippet Revision

Run an interactive C code-review drill focused on visual inspection, explanation quality, and practical debugging judgment.

## Core loop

- Show exactly one snippet at a time.
- Randomly choose Level 1 or Level 2 unless the user asks for a specific level or theme.
- After showing the snippet, ask only: `Tell me what’s wrong with the code presented.`
- Let the user answer in freeform.
- Then respond in this structure:
  1. brief judgment
  2. what they got right
  3. what they missed or should sharpen
  4. best concise interview framing
  5. next random snippet
- If the user says `Tell me`, explain the snippet directly and wait for the user to ask for the next one.

Keep the tone concise, practical, direct, and supportive. Avoid corporate filler.

## Interview style to emulate

Bias toward practical AI-led code review/debugging interviews rather than coding-from-scratch puzzles.

Encourage this answer pattern when helpful:
- intent
- main bug
- concrete failing case
- fix
- tests

Reward precision. Distinguish between:
- actual bug
- API contract ambiguity
- ownership assumption
- design/performance concern
- naming mismatch

Do not over-label bugs as use-after-free. Be precise.

## Levels

### Level 1

Use short, self-contained snippets. Focus on one or two sharp bugs.

Good Level 1 families:
- off-by-one loop bounds
- null pointer handling
- string termination mistakes
- `strncpy` / `strcpy` / `strcmp` / `strlen` / `strchr` / `memcpy` misuse
- signed vs unsigned traps
- divide by zero
- bad sentinel/error return conventions
- pointer-to-stack return bugs
- uninitialized reads
- invalid free
- use-after-free
- shallow vs deep copy mistakes
- incorrect pointer arithmetic
- bad boundary checks
- allocation-size overflow
- misleading comments vs behavior

### Level 2

Use more realistic fragments from a larger system. Prefer 2–5 related functions or a small struct plus helper functions.

Good Level 2 families:
- parser / packet decoding
- config/state update helpers
- ownership/lifetime across setter/destroy/copy functions
- linked-list / tree cleanup
- file/resource cleanup on error paths
- wrappers with hidden contracts
- append/logging/partial-write helpers
- initialization followed by uninitialized-state use
- duplicate logic with inconsistent fixes
- shallow copy leading to aliasing bugs
- mutability assumptions about input buffers / string literals
- header/payload or prefix/suffix validation mistakes
- stale state / invariant violations

Do not overproduce queue/ringbuffer/size_t-underflow clones. Maintain variety.

## Feedback guidance

Prefer high-signal coaching:
- validate correct instincts quickly
- identify the highest-value bug first
- correct subtle misconceptions cleanly
- note secondary issues without burying the main one
- give a strong interview-grade phrasing when useful

When a user focuses on a non-central issue, say so directly.

## Pointer-to-pointer and ownership topics

If the user is shaky on `T **` patterns, briefly explain with concrete caller-side examples before continuing.

Key clarifications to make when relevant:
- assigning through `*dst` updates the caller’s pointer
- assigning to local `dst` does not
- `free(ptr); ptr = other;` is not use-after-free by itself
- ownership bugs are different from dereferencing freed memory

## Safety / realism rules for snippet generation

- Keep snippets plausible C, not nonsense puzzles.
- Include standard headers consistent with the snippet when convenient, but do not let missing includes become the main bug unless intentionally testing that.
- Ensure there is a clear primary bug or cluster of related bugs.
- Do not require compiling or external tools; the drill is visual inspection only.
- Prefer practical engineering mistakes over obscure language-lawyer trivia.

## References

- Read `references/game-format.md` for the interactive flow, feedback format, and style rules.
- Read `references/error-pool.md` for the bug families and snippet-generation pool.
- Read `references/example-snippets.md` for starter examples and difficulty calibration.
- Read `references/interview-notes.md` when the user specifically wants AI-led or code-review-style interview prep.

## Packaging notes

Keep the skill lightweight and reusable:
- do not assume any prior session state
- start from Level 1 or Level 2 based on user request, otherwise choose randomly
- avoid repeating the same structural family several times in a row
- prefer one clear primary bug with a few secondary observations over bloated trick snippets
```

## File: README.md
size: 2495
sha: 1c2fb5892bfa1feaf1cdd18ded8350f34926b3c2
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/README.md

````text
# c-snippet-revision

`c-snippet-revision` is an installable skill for interactive C interview practice through visual code inspection.

It runs a one-at-a-time revision game built around short bug-spotting snippets and larger system-style code fragments. The emphasis is on reasoning clearly about correctness, ownership, boundaries, failure paths, and engineering judgment rather than compiling and running code.

## What it does

- presents exactly one C snippet at a time
- supports two difficulty levels:
  - **Level 1**: short, self-contained bug-spotting snippets
  - **Level 2**: larger multi-function or system-style fragments
- gives concise, interview-oriented feedback
- helps sharpen spoken debugging explanations
- supports practical code-review style interview prep

## Use cases

Use this skill when you want to:

- practice C debugging by visual inspection only
- rehearse code-review interview questions
- improve bug-spotting speed and precision
- train on ownership, memory safety, bounds, and error-path issues
- get one-snippet-at-a-time interactive feedback instead of bulk problem dumps

## How the revision loop works

1. get shown one snippet
2. get asked: `Tell me what’s wrong with the code presented.`
3. allowed to answer in freeform
4. feedback given on:
   - what you got right
   - what you missed
   - how to phrase the answer more sharply
5. move to the next snippet

## Skill contents

```text
c-snippet-revision/
├── SKILL.md
├── README.md
├── references/
│   ├── error-pool.md
│   ├── example-snippets.md
│   ├── game-format.md
│   └── interview-notes.md
└── dist/
    └── c-snippet-revision.skill
```

## Installation

Package the skill using the OpenClaw skill packaging tooling, then install the resulting `.skill` file using your usual skill installation flow.

Packaged artifact:

```text
/home/pi/c-snippet-revision/dist/c-snippet-revision.skill
```

## Development notes

This repository contains the source skill directory as well as the packaged `.skill` artifact.

If you edit the skill, repackage it with the skill creator.

## Design goals

- practical, realistic C bugs rather than puzzle trivia
- concise, high-signal feedback
- strong variety across snippet families
- reusable from a cold start without depending on prior chat history
- good support for both ownership-heavy and boundary-heavy debugging problems

## License

Add your preferred license here before publishing.
````

## File: references/error-pool.md
size: 1716
sha: 30acb6befa319d0fd99aff1dcbbef3e80bd95af9
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/references/error-pool.md

```text
# Error Pool

Use these families to generate a broad mix of snippets.

## Level 1

- off-by-one loop conditions
- string termination mistakes
- copy-size bugs
- destination-capacity vs source-length mismatch
- unchecked `strchr` / delimiter search failure
- unchecked `malloc` / `realloc`
- invalid free
- use-after-free
- returning pointer to local storage
- null pointer handling
- uninitialized heap or stack reads
- signed/unsigned comparisons
- modulo / division by zero
- bad sentinel/error conventions
- allocation-size overflow before malloc
- index arithmetic overflow
- hidden assumptions about valid digits / valid strings / valid lengths
- `memcmp` vs `strncmp` semantic mismatch
- copying raw bytes when string semantics were intended

## Level 2

- copy / clone functions with shallow-copy failure semantics
- setter/destroy ownership mismatches
- borrowed-view vs owning-buffer confusion
- helper function contract mismatch across multiple functions
- cleanup-path leaks
- partial initialization left behind on error
- linked list / tree cleanup order bugs
- parser functions that validate the wrong length field
- aliasing / lifetime hazards across returned pointers
- resource wrappers that free caller-owned inputs
- stale or inconsistent state after realloc/copy failure
- duplicate logic with one branch fixed and another not
- performance/design issues only when they are realistic and not the sole point

## Generation rules

- keep snippets plausible and readable
- avoid repeating queue/ringbuffer examples too often
- vary between memory safety, ownership, validation, API design, and partial failure cases
- prefer snippets where a strong engineer would reason verbally rather than compile
```

## File: references/example-snippets.md
size: 2426
sha: 0a786b35805b9e3d8709955abaeff576a4f0b57b
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/references/example-snippets.md

````text
# Example Snippets

Use these as calibration examples or seed patterns. Do not repeat them verbatim too often.

## Level 1 example

```c
#include <string.h>

int copy_word(char *dst, size_t dst_size, const char *src) {
    size_t len = strcspn(src, " ");
    if (len > dst_size) {
        return -1;
    }
    memcpy(dst, src, len);
    dst[len] = '\0';
    return 0;
}
```

Primary issue: off-by-one destination check. If `len == dst_size`, terminator write is out of bounds.

## Level 2 example

```c
#include <stdlib.h>
#include <string.h>

typedef struct {
    char *name;
    char *desc;
} item_t;

int item_copy(item_t *dst, const item_t *src) {
    *dst = *src;

    if (src->name) {
        dst->name = malloc(strlen(src->name) + 1);
        if (!dst->name) {
            return -1;
        }
        strcpy(dst->name, src->name);
    }

    if (src->desc) {
        dst->desc = malloc(strlen(src->desc) + 1);
        if (!dst->desc) {
            free(dst->name);
            return -1;
        }
        strcpy(dst->desc, src->desc);
    }

    return 0;
}
```

Primary issue: shallow-copy start plus unsafe failure semantics leaves `dst` in a partially copied/unsafe state.

## Pointer-to-pointer example

```c
#include <stdlib.h>
#include <string.h>

int append_exclamation(char **dst) {
    size_t len = strlen(*dst);
    char *tmp = realloc(*dst, len + 2);
    if (!tmp) {
        return -1;
    }

    tmp[len] = '!';
    tmp[len + 1] = '\0';
    return 0;
}
```

Primary issue: fails to assign `*dst = tmp` after realloc.

## Cleanup-path example

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
    char *name;
    FILE *fp;
} resource_t;

int resource_init(resource_t *r, const char *name, const char *path) {
    r->name = malloc(strlen(name) + 1);
    if (!r->name) {
        return -1;
    }
    strcpy(r->name, name);

    r->fp = fopen(path, "r");
    if (!r->fp) {
        return -1;
    }

    return 0;
}
```

Primary issue: if `fopen` fails, the function leaks `r->name` on the error path.

## Validation example

```c
#include <string.h>

int has_suffix(const char *name, const char *suffix) {
    size_t name_len = strlen(name);
    size_t suffix_len = strlen(suffix);

    return strcmp(name + (name_len - suffix_len), suffix) == 0;
}
```

Primary issue: if `suffix_len > name_len`, the subtraction underflows and the pointer passed to `strcmp` becomes invalid.
````

## File: references/game-format.md
size: 1311
sha: 6ba00fdd2957a6232816d0327932df31cff447bf
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/references/game-format.md

```text
# Game Format

## Default loop

1. Present exactly one C snippet.
2. Ask only: `Tell me what’s wrong with the code presented.`
3. Let the user answer in freeform.
4. Respond with:
   - brief judgment
   - what they got right
   - what they missed or should sharpen
   - best concise interview framing
   - next snippet

If the user says `Tell me`, explain the snippet directly without forcing them to answer first.

## Tone

- concise
- direct
- practical
- lightly sharp but supportive
- no filler praise

## Coaching priorities

- prioritize the highest-value bug
- distinguish correctness bug vs API/design concern
- call out when the user has spotted a real issue but not the main one
- use concrete examples when clarification matters
- encourage precise language: underflow, invalid free, dangling pointer, off-by-one, ownership confusion, partial failure state, etc.

## Good response starters

- `Yep — that’s the main bug.`
- `Close, but the central issue is slightly different.`
- `You caught a real issue, but not the highest-value one.`
- `That’s a fair API concern, but the actual bug is...`

## Interview framing pattern

When helpful, produce a short answer the user could say in an interview:

1. intent
2. main bug
3. concrete failure case
4. fix
5. optional test cases

Keep it tight.
```

## File: references/interview-notes.md
size: 906
sha: 095a471191813768769a62b80564a4fcf4239619
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/references/interview-notes.md

```text
# Interview Notes

Use this reference when the user specifically wants AI-led or practical code-review-style interview prep.

## Typical constraints

- Examples are in C.
- The user may not be allowed to use tools; debugging may be visual inspection only.
- Common structure:
  - Level 1: short bug-spotting snippets
  - Level 2: a few functions from a larger C system with a realistic error

## Best emulation style

- Ask the user to explain what the code is trying to do, what the bug is, what failing case exposes it, how to fix it, and what tests to run.
- Reward concise spoken-debugging structure.
- Prefer practical bugs over puzzle-like tricks.
- Bias toward code review / reasoning clarity rather than coding from scratch.

## Good answer structure to coach

1. `This function is trying to...`
2. `The main bug is...`
3. `A concrete failing case is...`
4. `I’d fix it by...`
5. `I’d test...`
```

## File: LICENSE
size: 1070
sha: 384372c20e8acb7eb323cba9c7ba274297693823
upstream: https://github.com/jordmorr/openclaw-c-snippet-revision/blob/HEAD/LICENSE

```text
MIT License

Copyright (c) 2026 Jordan Morris

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
