One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
167 lines
4.0 KiB
C
167 lines
4.0 KiB
C
#include "scanner.h"
|
|
#include <limits.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
typedef struct {
|
|
const unsigned char *next;
|
|
} sp_reader;
|
|
|
|
static int horizontal(unsigned char character)
|
|
{
|
|
return character == ' ' || character == '\t' || character == '\r';
|
|
}
|
|
|
|
static void skip_space(sp_reader *reader)
|
|
{
|
|
while (horizontal(*reader->next)) {
|
|
reader->next += 1;
|
|
}
|
|
}
|
|
|
|
static int at_end(sp_reader *reader)
|
|
{
|
|
skip_space(reader);
|
|
return *reader->next == 0;
|
|
}
|
|
|
|
static int read_integer(sp_reader *reader, int lower, int upper, int *value)
|
|
{
|
|
const unsigned char *cursor;
|
|
unsigned int magnitude = 0;
|
|
int negative = 0;
|
|
int overflow = 0;
|
|
int digit_seen = 0;
|
|
skip_space(reader);
|
|
cursor = reader->next;
|
|
if (*cursor == '+' || *cursor == '-') {
|
|
negative = *cursor == '-';
|
|
cursor += 1;
|
|
}
|
|
while (*cursor >= '0' && *cursor <= '9') {
|
|
unsigned int digit = (unsigned int)(*cursor - '0');
|
|
digit_seen = 1;
|
|
if (magnitude > 100000u) {
|
|
overflow = 1;
|
|
} else {
|
|
magnitude = magnitude * 10u + digit;
|
|
}
|
|
cursor += 1;
|
|
}
|
|
if (!digit_seen || (*cursor && !horizontal(*cursor))) {
|
|
return -1;
|
|
}
|
|
if (overflow || magnitude > INT_MAX) {
|
|
return -1;
|
|
}
|
|
*value = negative ? -(int)magnitude : (int)magnitude;
|
|
if (*value < lower || *value > upper) {
|
|
return -1;
|
|
}
|
|
reader->next = cursor;
|
|
return 0;
|
|
}
|
|
|
|
static int read_plan(sp_reader *reader, sp_command *command)
|
|
{
|
|
int index;
|
|
sp_plan *plan = &command->plan;
|
|
if (read_integer(reader, 0, SP_MAX_ITEMS, &plan->count)) {
|
|
return -1;
|
|
}
|
|
if (read_integer(reader, 0, SP_MAX_ITEMS - 1, &plan->first)) {
|
|
return -1;
|
|
}
|
|
if (read_integer(reader, 0, SP_MAX_ITEMS - 1, &plan->last)) {
|
|
return -1;
|
|
}
|
|
if (read_integer(reader, 1, 17, &plan->modulus)) {
|
|
return -1;
|
|
}
|
|
if (read_integer(reader, 0, 16, &plan->residue)) {
|
|
return -1;
|
|
}
|
|
for (index = 0; index < plan->count; ++index) {
|
|
if (read_integer(reader, -1000, 1000, &plan->values[index])) {
|
|
return -1;
|
|
}
|
|
}
|
|
if (!at_end(reader) || !sp_plan_valid(plan)) {
|
|
return -1;
|
|
}
|
|
command->kind = SP_CMD_PLAN;
|
|
return 0;
|
|
}
|
|
|
|
int sp_decode(const char *text, sp_command *command)
|
|
{
|
|
sp_reader reader;
|
|
unsigned char operation;
|
|
memset(command, 0, sizeof(*command));
|
|
reader.next = (const unsigned char *)text;
|
|
skip_space(&reader);
|
|
operation = *reader.next;
|
|
if (!operation) {
|
|
return -1;
|
|
}
|
|
reader.next += 1;
|
|
if (*reader.next && !horizontal(*reader.next)) {
|
|
return -1;
|
|
}
|
|
if (operation == 'P') {
|
|
return read_plan(&reader, command);
|
|
}
|
|
if (operation == 'T') {
|
|
if (read_integer(&reader, 0, SP_MAX_BUDGET, &command->budget)) {
|
|
return -1;
|
|
}
|
|
command->kind = SP_CMD_TICK;
|
|
} else if (operation == 'S') {
|
|
command->kind = SP_CMD_SNAPSHOT;
|
|
} else if (operation == 'R') {
|
|
command->kind = SP_CMD_RESTART;
|
|
} else {
|
|
return -1;
|
|
}
|
|
if (!at_end(&reader)) {
|
|
command->kind = SP_CMD_INVALID;
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int sp_read_line(FILE *input, char **buffer, size_t *capacity)
|
|
{
|
|
size_t used = 0;
|
|
int character;
|
|
if (!*buffer) {
|
|
*capacity = 128;
|
|
*buffer = malloc(*capacity);
|
|
if (!*buffer) {
|
|
return -1;
|
|
}
|
|
}
|
|
while ((character = fgetc(input)) != EOF && character != '\n') {
|
|
if (used + 1 >= *capacity) {
|
|
size_t larger;
|
|
char *replacement;
|
|
if (*capacity > SIZE_MAX / 2) {
|
|
return -1;
|
|
}
|
|
larger = *capacity * 2;
|
|
replacement = realloc(*buffer, larger);
|
|
if (!replacement) {
|
|
return -1;
|
|
}
|
|
*buffer = replacement;
|
|
*capacity = larger;
|
|
}
|
|
(*buffer)[used++] = (char)character;
|
|
}
|
|
if (character == EOF && used == 0) {
|
|
return 0;
|
|
}
|
|
(*buffer)[used] = 0;
|
|
return 1;
|
|
}
|