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>
70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
#include "attribute.hpp"
|
|
#include <limits>
|
|
#include <cstring>
|
|
#include <cstdlib>
|
|
#include <cerrno>
|
|
namespace attr {
|
|
bool valid_name(const std::string& name)
|
|
{
|
|
if (name.empty()) {
|
|
return false;
|
|
}
|
|
if (name.size() > 24) {
|
|
return false;
|
|
}
|
|
for (unsigned char ch : name) {
|
|
if (ch >= 'a' && ch <= 'z') {
|
|
continue;
|
|
}
|
|
if (ch >= '0' && ch <= '9') {
|
|
continue;
|
|
}
|
|
if (ch == '_') {
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
int parse_value(const std::string& bytes, int32_t& output)
|
|
{
|
|
if (bytes.empty() || bytes.size() > 4096) {
|
|
return invalid;
|
|
}
|
|
size_t end = bytes.size();
|
|
if (bytes[end - 1] == '\n') {
|
|
--end;
|
|
}
|
|
if (end == 0) {
|
|
return invalid;
|
|
}
|
|
|
|
std::string token = bytes.substr(0, end);
|
|
errno = 0;
|
|
char* stopped = nullptr;
|
|
long long value = std::strtoll(token.c_str(), &stopped, 10);
|
|
if (stopped != token.c_str() + token.size() || stopped == token.c_str()) {
|
|
return invalid;
|
|
}
|
|
if (errno == ERANGE || value < -2147483648LL || value > 2147483647LL) {
|
|
return range;
|
|
}
|
|
output = static_cast<int32_t>(value);
|
|
return 0;
|
|
}
|
|
int format_value(int32_t value, char* output, size_t capacity)
|
|
{
|
|
if (output == nullptr) {
|
|
return invalid;
|
|
}
|
|
std::string formatted = std::to_string(value);
|
|
formatted.push_back('\n');
|
|
if (capacity <= formatted.size()) {
|
|
return full;
|
|
}
|
|
std::memcpy(output, formatted.data(), formatted.size());
|
|
output[formatted.size()] = '\0';
|
|
return static_cast<int>(formatted.size());
|
|
}
|
|
}
|