Checkpoint: Ring Forensics
Challenge on lesson: Checkpoint: Forensic Engine
A ring buffer's public fields live in your editor (struct ring { int buf[8]; size_t head, tail, count; };). Implement three verdicts:\n1. bool ring_size_ok(const struct ring *r) โ count <= capacity 8, and head/tail in [0, 8).\n2. bool ring_count_matches(const struct ring *r, size_t expected) โ the recorded count equals the actual occupancy derived from head/tail/count consistency (here: count <= 8 && head < 8 && tail < 8 && (r->count == 0 ? r->head == r->tail : true)).\n3. const char *diagnose(const struct ring *r) โ return "ok" when both verdicts hold; "size-corrupt" when sizes are out of range; "index-corrupt" when head or tail is out of range (checked first).
Back to lesson: Checkpoint: Forensic Engine