Now allowing 000 as score.
h3rald h3rald@h3rald.com
Fri, 12 Jun 2026 11:10:49 +0200
2 files changed,
51 insertions(+),
26 deletions(-)
M
src/conver.c
→
src/conver.c
@@ -177,7 +177,7 @@ if (vscore >= 0x801 && vscore <= 0xC00) { return CONVER_STAGE_CONSOLIDATED; }
return CONVER_STAGE_BEDROCK; } -conver_impact_t size(uint16_t version) +conver_impact_t impact(uint16_t version) { uint16_t meta = metadata(version); if (meta >= 0xC) { return CONVER_IMPACT_C; }@@ -207,6 +207,30 @@ snprintf(dest, dest_size, "%04d-%02d-%02d", d.tm_year + 1900, d.tm_mon + 1, d.tm_mday);
return dest; } + +int parse_hex(const char *str, uint16_t *out_val) { + if (str == NULL || *str == '\0') { + return CONVER_ERR_INVALID_VALUE; + } + char *endptr; + errno = 0; + uint16_t val = strtoul(str, &endptr, 16); + if (errno == ERANGE) { + return CONVER_ERR_INVALID_VALUE; + } + if (endptr == str) { + return CONVER_ERR_INVALID_VALUE; + } + while (*endptr != '\0') { + if (!isspace((unsigned char)*endptr)) { + return CONVER_ERR_INVALID_VALUE; + } + endptr++; + } + *out_val = val; + return CONVER_OK; +} + int parse_release(const char *line, conver_release_t *r) { char sign; char number[5];@@ -219,8 +243,9 @@ }
if (!set_release_date(r, year, month, day)) { return print_result(CONVER_ERR_INVALID_DATE); } - uint16_t version = strtoul(number, NULL, 16); - if (!version) { + uint16_t version; + int result = parse_hex(number, &version); + if (result != CONVER_OK) { return print_result(CONVER_ERR_INVALID_DATE); } r->score = score(version);@@ -258,7 +283,7 @@
void print_version(uint16_t version) { printf(" v%03X-%1X (Stage: %s)\n", score(version), metadata(version), conver_stages[stage(version)]); - printf(" Impact: %s - Compatibility: %s - Purpose: %s\n", conver_impacts[size(version)], conver_compatibilities[compatibility(version)], conver_purposes[purpose(version)]); + printf(" Impact: %s - Compatibility: %s - Purpose: %s\n", conver_impacts[impact(version)], conver_compatibilities[compatibility(version)], conver_purposes[purpose(version)]); } int parse_history() {@@ -319,8 +344,6 @@ }
return CONVER_OK; } - - //// Commands int command_init()@@ -369,7 +392,7 @@ char score[16];
uint16_t version; int valid = 0; while (!valid) { - printf("> Specify the dependability score of the release [001-FFF]: "); + printf("> Specify the dependability score of the release [000-FFF]: "); fgets(score, sizeof(score), stdin); if (strlen(score) > 4) { print_result(CONVER_ERR_INVALID_VALUE);@@ -387,8 +410,8 @@ if (invalid_digit) {
print_result(CONVER_ERR_INVALID_VALUE); continue; } - version = strtoul(score, NULL, 16); - if (!version) { + result = parse_hex(score, &version); + if (result != CONVER_OK) { print_result(CONVER_ERR_INVALID_VALUE); continue; }@@ -404,24 +427,24 @@ valid = 1;
} version = version << 4; // left shift to make room for metadata nibble valid = 0; - char size[16]; + char impact[16]; while (!valid) { - printf("> Specify the size of the release [S, M, L, X]: "); - fgets(size, sizeof(size), stdin); - if (strlen(size)> 2) { + printf("> Specify the impact of the release [L, M, H, C]: "); + fgets(impact, sizeof(impact), stdin); + if (strlen(impact)> 2) { print_result(CONVER_ERR_INVALID_VALUE); continue; } - if (size[0] == 's' || size[0] == 'S') { + if (impact[0] == 'l' || impact[0] == 'L') { version += 0x3; } - else if (size[0] == 'm' || size[0] == 'M') { + else if (impact[0] == 'm' || impact[0] == 'M') { version += 0x7; } - else if (size[0] == 'l' || size[0] == 'L') { + else if (impact[0] == 'h' || impact[0] == 'H') { version += 0xB; } - else if (size[0] == 'x' || size[0] == 'X') { + else if (impact[0] == 'c' || impact[0] == 'C') { version += 0xF; } else {@@ -476,9 +499,9 @@ result = fs_write(CONVER_DRAFT_FILE, version_string);
print_result(result); memset(version_string, 0, sizeof(version_string)); memset(score, 0, sizeof(score)); - memset(size,0,sizeof(size)); - memset(breaking,0,sizeof(breaking)); - memset(enhancement,0,sizeof(enhancement)); + memset(impact, 0, sizeof(impact)); + memset(breaking, 0, sizeof(breaking)); + memset(enhancement, 0, sizeof(enhancement)); return result; }@@ -497,8 +520,9 @@ }
if (strlen(draft_string) != 4) { return print_result(CONVER_ERR_NO_DRAFT); } - uint16_t draft = strtoul(draft_string, NULL, 16); - if (!draft) { + uint16_t draft; + result = parse_hex(draft_string, &draft); + if (result != CONVER_OK) { return print_result(CONVER_ERR_INVALID_DRAFT); } time_t timestamp = time(NULL);@@ -555,8 +579,8 @@ if (result != CONVER_OK) {
return print_result(result); } if (strlen(draft_string) == 4) { - draft = strtoul(draft_string, NULL, 16); - if (!draft) { + result = parse_hex(draft_string, &draft); + if (result != CONVER_OK) { return print_result(CONVER_ERR_INVALID_DRAFT); } }@@ -565,8 +589,8 @@ if (result != CONVER_OK) {
return print_result(result); } if (strlen(release_string) == 4) { - release = strtoul(release_string, NULL, 16); - if (!release) { + result = parse_hex(release_string, &release); + if (result != CONVER_OK) { return print_result(CONVER_ERR_INVALID_RELEASE); } }
M
src/conver.h
→
src/conver.h
@@ -14,6 +14,7 @@ #include <stdio.h>
#include <stdlib.h> #include <stdint.h> #include <string.h> +#include <errno.h> #include <ctype.h> #include <time.h> #include <stdbool.h>