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>
145 lines
4.1 KiB
C
145 lines
4.1 KiB
C
#include "render_api.h"
|
|
#include <string.h>
|
|
struct text_writer {
|
|
char *data;
|
|
size_t capacity;
|
|
size_t used;
|
|
size_t required;
|
|
};
|
|
static void writer_init(struct text_writer *writer, char *data, size_t capacity)
|
|
{
|
|
writer->data = data;
|
|
writer->capacity = capacity;
|
|
writer->used = 0;
|
|
writer->required = 0;
|
|
if (capacity != 0 && data != NULL) {
|
|
data[0] = '\0';
|
|
}
|
|
}
|
|
static void writer_byte(struct text_writer *writer, unsigned char value)
|
|
{
|
|
if (writer->data != NULL && writer->capacity != 0 &&
|
|
writer->used + 1 < writer->capacity) {
|
|
writer->data[writer->used++] = (char)value;
|
|
writer->data[writer->used] = '\0';
|
|
}
|
|
writer->required++;
|
|
}
|
|
static void writer_text(struct text_writer *writer, const char *text)
|
|
{
|
|
while (*text != '\0') {
|
|
writer_byte(writer, (unsigned char)*text);
|
|
text++;
|
|
}
|
|
}
|
|
static void writer_unsigned(struct text_writer *writer, uint32_t value)
|
|
{
|
|
char digits[10];
|
|
size_t count = 0;
|
|
do {
|
|
digits[count++] = (char)('0' + value % 10);
|
|
value /= 10;
|
|
} while (value != 0);
|
|
while (count != 0) {
|
|
writer_byte(writer, (unsigned char)digits[--count]);
|
|
}
|
|
}
|
|
static void writer_signed(struct text_writer *writer, int32_t value)
|
|
{
|
|
uint32_t magnitude;
|
|
if (value < 0) {
|
|
writer_byte(writer, '-');
|
|
magnitude = (uint32_t)(-(int64_t)value);
|
|
} else {
|
|
magnitude = (uint32_t)value;
|
|
}
|
|
writer_unsigned(writer, magnitude);
|
|
}
|
|
static char hex_digit(unsigned value)
|
|
{
|
|
return "0123456789abcdef"[value & 15U];
|
|
}
|
|
static void writer_escape(struct text_writer *writer, unsigned char value)
|
|
{
|
|
if (value == '"' || value == '\\') {
|
|
writer_byte(writer, '\\');
|
|
writer_byte(writer, value);
|
|
} else if (value >= 32 && value <= 126) {
|
|
writer_byte(writer, value);
|
|
} else {
|
|
writer_text(writer, "\\u00");
|
|
writer_byte(writer, (unsigned char)hex_digit(value >> 4));
|
|
writer_byte(writer, (unsigned char)hex_digit(value));
|
|
}
|
|
}
|
|
static void writer_record(struct text_writer *writer, const struct record *record)
|
|
{
|
|
writer_text(writer, "{\"id\":");
|
|
writer_signed(writer, record->identifier);
|
|
writer_text(writer, ",\"level\":");
|
|
writer_unsigned(writer, record->level);
|
|
writer_text(writer, ",\"value\":");
|
|
writer_signed(writer, record->value);
|
|
writer_text(writer, ",\"label\":\"");
|
|
for (size_t index = 0; index < record->label_length; index++) {
|
|
writer_escape(writer, record->label[index]);
|
|
}
|
|
writer_text(writer, "\"}");
|
|
}
|
|
size_t codec_record_size(const struct record *record)
|
|
{
|
|
struct text_writer writer;
|
|
writer_init(&writer, NULL, 0);
|
|
writer_record(&writer, record);
|
|
return writer.required;
|
|
}
|
|
size_t codec_record_write(const struct record *record, char *target, size_t capacity)
|
|
{
|
|
struct text_writer writer;
|
|
writer_init(&writer, target, capacity);
|
|
writer_record(&writer, record);
|
|
return writer.used;
|
|
}
|
|
static int hex_value(unsigned char value)
|
|
{
|
|
if (value >= '0' && value <= '9') {
|
|
return value - '0';
|
|
}
|
|
if (value >= 'a' && value <= 'f') {
|
|
return value - 'a' + 10;
|
|
}
|
|
if (value >= 'A' && value <= 'F') {
|
|
return value - 'A' + 10;
|
|
}
|
|
return -1;
|
|
}
|
|
int codec_hex_decode(const char *text, unsigned char *out, size_t *length)
|
|
{
|
|
size_t size = strlen(text);
|
|
if (strcmp(text, "-") == 0) {
|
|
*length = 0;
|
|
return 1;
|
|
}
|
|
if (size == 0 || size % 2 != 0 || size / 2 > LABEL_LIMIT) {
|
|
return 0;
|
|
}
|
|
for (size_t index = 0; index < size / 2; index++) {
|
|
int high = hex_value((unsigned char)text[index * 2]);
|
|
int low = hex_value((unsigned char)text[index * 2 + 1]);
|
|
if (high < 0 || low < 0) {
|
|
return 0;
|
|
}
|
|
out[index] = (unsigned char)(high * 16 + low);
|
|
}
|
|
*length = size / 2;
|
|
return 1;
|
|
}
|
|
uint32_t codec_digest(uint32_t previous, const unsigned char *data, size_t length)
|
|
{
|
|
uint32_t value = previous;
|
|
for (size_t index = 0; index < length; index++) {
|
|
value = value * UINT32_C(33) + data[index] + UINT32_C(1);
|
|
}
|
|
return value;
|
|
}
|