Add collision-safe status code registry

Replace the consumer-sized status-name array with private sparse storage and accept arbitrary integer status values. Add explicit range reservations with overlap diagnostics, reserve the library's 0-255 compatibility band, and harden pointer and string boundary handling.

Update regression coverage and document the required migration for custom status-code consumers.
This commit is contained in:
2026-07-30 13:53:39 -04:00
parent 0bb3a4d52c
commit 11d21068df
9 changed files with 250 additions and 260 deletions

View File

@@ -2,13 +2,7 @@
#include "err_capture.h"
#include <string.h>
/*
* akerr_name_for_status must reject out-of-range status codes at BOTH ends.
* It already guarded the upper bound, but a negative status indexed
* __AKERR_ERROR_NAMES[negative] -- an out-of-bounds read (and an out-of-bounds
* write when a name is supplied). Every out-of-range status must return the
* "Unknown Error" sentinel instead.
*/
/* Unregistered status values return the sentinel regardless of magnitude. */
int main(void)
{
@@ -18,8 +12,7 @@ int main(void)
AKERR_CHECK(strcmp(akerr_name_for_status(-1, NULL), "Unknown Error") == 0);
AKERR_CHECK(strcmp(akerr_name_for_status(-9999, NULL), "Unknown Error") == 0);
/* Above range (already handled; kept as a guard against regressions). */
AKERR_CHECK(strcmp(akerr_name_for_status(AKERR_MAX_ERR_VALUE + 1, NULL),
AKERR_CHECK(strcmp(akerr_name_for_status(1000000, NULL),
"Unknown Error") == 0);
/* A valid code must still resolve to its real name. */