amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

36 lines
885 B
C

#include "stack_domain.h"
static int append_digit(uint64_t current, unsigned char byte, uint64_t *next)
{
uint64_t digit;
if (byte < '0' || byte > '9') {
return SD_EINVAL;
}
digit = (uint64_t)(byte - '0');
if (current > UINT64_MAX / 10) {
return SD_EINVAL;
}
if (current == UINT64_MAX / 10 && digit > UINT64_MAX % 10) {
return SD_EINVAL;
}
*next = current * 10 + digit;
return SD_OK;
}
int sd_number(const unsigned char *text, size_t length, uint64_t *out)
{
size_t i;
uint64_t value = 0;
if (text == NULL || out == NULL || length == 0) {
return SD_EINVAL;
}
for (i = 0; i < length; ++i) {
uint64_t next;
int rc = append_digit(value, text[i], &next);
if (rc != SD_OK) {
return rc;
}
value = next;
}
*out = value;
return SD_OK;
}