amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

89 lines
2.4 KiB
C

#include "text.h"
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
static int grow(char **buffer, size_t *capacity)
{
size_t next;
char *copy;
if (*capacity > SIZE_MAX / 2) return -1;
next = *capacity ? *capacity * 2 : 128;
copy = realloc(*buffer, next);
if (copy == NULL) return -1;
*buffer = copy;
*capacity = next;
return 0;
}
int text_line(FILE *stream, char **buffer, size_t *capacity)
{
size_t length = 0;
int ch;
if (stream == NULL || buffer == NULL || capacity == NULL) return -1;
for (;;) {
ch = fgetc(stream);
if (ch == EOF) return -1;
if (ch == '\n') break;
if (length + 2 > *capacity && grow(buffer, capacity)) return -1;
(*buffer)[length++] = (char)ch;
}
if (length && (*buffer)[length - 1] == '\r') length--;
if (length == 0) return -1;
(*buffer)[length] = '\0';
return 0;
}
int text_decimal(const char *begin, const char *end, unsigned long *number)
{
unsigned long value = 0;
const unsigned char *at = (const unsigned char *)begin;
if (begin == NULL || end == NULL || number == NULL) return -1;
if (begin == end) return -1;
while (at < (const unsigned char *)end && *at == '0') at++;
while (at < (const unsigned char *)end) {
unsigned digit;
if (*at < '0' || *at > '9') return -1;
digit = (unsigned)(*at - '0');
if (value > (ULONG_MAX - digit) / 10) return -1;
value = value * 10 + digit;
at++;
}
*number = value;
return 0;
}
int text_fields(char *buffer, unsigned long *numbers, size_t count)
{
char *begin = buffer;
char *at = buffer;
size_t index = 0;
if (buffer == NULL || numbers == NULL || count == 0) return -1;
if (*buffer == ' ' || *buffer == '\t') return -1;
while (*at) {
if (*at == ' ') {
if (index >= count || text_decimal(begin, at, &numbers[index])) return -1;
index++;
at++;
if (*at == ' ' || *at == '\0') return -1;
begin = at;
continue;
}
if (*at == '\t' || *at == '\r' || *at == '\n') return -1;
at++;
}
if (index != count - 1) return -1;
return text_decimal(begin, at, &numbers[index]);
}
int text_end(FILE *stream)
{
int ch;
if (stream == NULL) return -1;
ch = fgetc(stream);
if (ch != EOF) return -1;
if (ferror(stream)) return -1;
return 0;
}