Port onto libakstdlib 2b79aca and convert the eight bool predicates
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 3m27s
akbasic CI Build / coverage (push) Failing after 3m44s
akbasic CI Build / sanitizers (push) Failing after 4m43s
akbasic CI Build / mutation_test (push) Failing after 3m45s
akbasic CI Build / akgl_build (push) Failing after 4m51s
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 3m27s
akbasic CI Build / coverage (push) Failing after 3m44s
akbasic CI Build / sanitizers (push) Failing after 4m43s
akbasic CI Build / mutation_test (push) Failing after 3m45s
akbasic CI Build / akgl_build (push) Failing after 4m51s
akbasic's src/ now calls libakstdlib 313 times and raw libc 7 -- 2.2% bypassed, against 86.4% on the same tree before this. The submodule bump 669b2b3 -> 2b79aca needed no source change of its own: the release is drop-in for what akbasic already used. Seven of the eight sites the earlier port left on raw libc change their own signature rather than swallowing an error, per andrew's ruling on libakstdlib#38. word_is, the is_waiting_for pair, the scanner's is_at_end, peek, peek_next and match_next_char, format.c's overflow, and sink_akgl's scroll/newline/putchar_at/echo_line/edit_key chain all return an akerr_ErrorContext * and hand the answer back through an out parameter. is_waiting_for and is_waiting_for_any are a public header change; every call site that used one as a term in a condition hoists it into a statement first. verb_compare is the eighth and stays on strcmp. bsearch(3) fixes the comparator's signature, so there is no out parameter to report through -- which is what libakstdlib#38 concluded. It carries a comment saying so and saying why the bypass is safe there. Six snprintf sites stay raw because they want truncation as an answer rather than an error, and aksl_snprintf cannot express that until libakstdlib#34 hands the required length back. Each of the six says so at the site. Two of them, in host.c, are a latent defect rather than a decision: a host type name over 31 characters truncates silently and two sharing a prefix then collide, where structtype.c refuses the same case. DLOAD leaked a file descriptor. Its read loop sat inside an ATTEMPT and the PASS in it returned past CLEANUP, so a scan error left the file open. Hoisting the loop into its own helper to convert fgets fixes it. Refs libakstdlib#26, libakstdlib#38 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,14 +17,19 @@
|
||||
static akerr_ErrorContext *copy_bounded(char *dest, const char *src, const char *what)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
size_t srclen = 0;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (src != NULL), AKERR_NULLPOINTER, "NULL %s", what);
|
||||
FAIL_ZERO_RETURN(errctx, (strlen(src) < AKBASIC_MAX_STRING_LENGTH),
|
||||
PASS(errctx, aksl_strlen(src, &srclen));
|
||||
FAIL_ZERO_RETURN(errctx, (srclen < AKBASIC_MAX_STRING_LENGTH),
|
||||
AKBASIC_ERR_VALUE,
|
||||
"%s of %zu characters exceeds the %d character limit",
|
||||
what, strlen(src), AKBASIC_MAX_STRING_LENGTH - 1);
|
||||
strncpy(dest, src, AKBASIC_MAX_STRING_LENGTH - 1);
|
||||
dest[AKBASIC_MAX_STRING_LENGTH - 1] = '\0';
|
||||
what, srclen, AKBASIC_MAX_STRING_LENGTH - 1);
|
||||
/* aksl_strcpy always terminates and refuses rather than truncates, which is
|
||||
the behaviour this site already wanted. The length check above stays
|
||||
because it names the limit in the message. Every destination is one of the
|
||||
leaf's AKBASIC_MAX_STRING_LENGTH buffers, which is what sizes the copy. */
|
||||
PASS(errctx, aksl_strcpy(dest, AKBASIC_MAX_STRING_LENGTH, src));
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -90,8 +95,8 @@ static akerr_ErrorContext *clone_into(akbasic_ASTLeaf *self, akbasic_LeafPool *p
|
||||
copy->parent = self->parent;
|
||||
copy->literal_int = self->literal_int;
|
||||
copy->literal_float = self->literal_float;
|
||||
memcpy(copy->literal_string, self->literal_string, sizeof(copy->literal_string));
|
||||
memcpy(copy->identifier, self->identifier, sizeof(copy->identifier));
|
||||
PASS(errctx, aksl_memcpy(copy->literal_string, self->literal_string, sizeof(copy->literal_string)));
|
||||
PASS(errctx, aksl_memcpy(copy->identifier, self->identifier, sizeof(copy->identifier)));
|
||||
copy->operator_ = self->operator_;
|
||||
|
||||
PASS(errctx, clone_into(self->left, pool, ©->left));
|
||||
@@ -289,7 +294,9 @@ akerr_ErrorContext *akbasic_leaf_new_literal_int(akbasic_ASTLeaf *obj, const cha
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
long long value = 0;
|
||||
size_t lexlen = 0;
|
||||
int base = 10;
|
||||
int cmp = 0;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (obj != NULL), AKERR_NULLPOINTER, "NULL leaf in new_literal_int");
|
||||
FAIL_ZERO_RETURN(errctx, (lexeme != NULL), AKERR_NULLPOINTER, "NULL lexeme in new_literal_int");
|
||||
@@ -302,7 +309,9 @@ akerr_ErrorContext *akbasic_leaf_new_literal_int(akbasic_ASTLeaf *obj, const cha
|
||||
* Commodore BASIC has no octal literals, and a leading zero in a listing is
|
||||
* padding, not a radix.
|
||||
*/
|
||||
if ( strlen(lexeme) > 2 && strncmp(lexeme, "0x", 2) == 0 ) {
|
||||
PASS(errctx, aksl_strlen(lexeme, &lexlen));
|
||||
PASS(errctx, aksl_strncmp(lexeme, "0x", 2, &cmp));
|
||||
if ( lexlen > 2 && cmp == 0 ) {
|
||||
base = 16;
|
||||
}
|
||||
PASS(errctx, akbasic_leaf_init(obj, AKBASIC_LEAF_LITERAL_INT));
|
||||
@@ -388,6 +397,7 @@ akerr_ErrorContext *akbasic_leaf_to_string(akbasic_ASTLeaf *self, char *dest, si
|
||||
PREPARE_ERROR(errctx);
|
||||
char sub1[AKBASIC_MAX_STRING_LENGTH];
|
||||
char sub2[AKBASIC_MAX_STRING_LENGTH];
|
||||
int written = 0;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, (self != NULL), AKERR_NULLPOINTER, "NULL leaf in to_string");
|
||||
FAIL_ZERO_RETURN(errctx, (dest != NULL), AKERR_NULLPOINTER, "NULL destination in to_string");
|
||||
@@ -395,40 +405,42 @@ akerr_ErrorContext *akbasic_leaf_to_string(akbasic_ASTLeaf *self, char *dest, si
|
||||
|
||||
switch ( self->leaftype ) {
|
||||
case AKBASIC_LEAF_LITERAL_INT:
|
||||
snprintf(dest, len, "%" PRId64, self->literal_int);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%" PRId64, self->literal_int));
|
||||
break;
|
||||
case AKBASIC_LEAF_LITERAL_FLOAT:
|
||||
snprintf(dest, len, "%f", self->literal_float);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%f", self->literal_float));
|
||||
break;
|
||||
case AKBASIC_LEAF_LITERAL_STRING:
|
||||
snprintf(dest, len, "%s", self->literal_string);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%s", self->literal_string));
|
||||
break;
|
||||
case AKBASIC_LEAF_IDENTIFIER_INT:
|
||||
case AKBASIC_LEAF_IDENTIFIER_FLOAT:
|
||||
case AKBASIC_LEAF_IDENTIFIER_STRING:
|
||||
case AKBASIC_LEAF_IDENTIFIER:
|
||||
snprintf(dest, len, "%s", self->identifier);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%s", self->identifier));
|
||||
break;
|
||||
case AKBASIC_LEAF_IDENTIFIER_STRUCT:
|
||||
snprintf(dest, len, "%s", self->identifier);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%s", self->identifier));
|
||||
break;
|
||||
case AKBASIC_LEAF_FIELD:
|
||||
PASS(errctx, akbasic_leaf_to_string(self->left, sub1, sizeof(sub1)));
|
||||
snprintf(dest, len, "%s%s%s", sub1,
|
||||
(self->operator_ == AKBASIC_TOK_ARROW ? "->" : "."), self->identifier);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "%s%s%s", sub1,
|
||||
(self->operator_ == AKBASIC_TOK_ARROW ? "->" : "."), self->identifier));
|
||||
break;
|
||||
case AKBASIC_LEAF_UNARY:
|
||||
PASS(errctx, akbasic_leaf_to_string(self->left, sub1, sizeof(sub1)));
|
||||
snprintf(dest, len, "(%s %s)", operator_to_str(self->operator_), sub1);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "(%s %s)",
|
||||
operator_to_str(self->operator_), sub1));
|
||||
break;
|
||||
case AKBASIC_LEAF_BINARY:
|
||||
PASS(errctx, akbasic_leaf_to_string(self->left, sub1, sizeof(sub1)));
|
||||
PASS(errctx, akbasic_leaf_to_string(self->right, sub2, sizeof(sub2)));
|
||||
snprintf(dest, len, "(%s %s %s)", operator_to_str(self->operator_), sub1, sub2);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "(%s %s %s)",
|
||||
operator_to_str(self->operator_), sub1, sub2));
|
||||
break;
|
||||
case AKBASIC_LEAF_GROUPING:
|
||||
PASS(errctx, akbasic_leaf_to_string(self->expr, sub1, sizeof(sub1)));
|
||||
snprintf(dest, len, "(group %s)", sub1);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "(group %s)", sub1));
|
||||
break;
|
||||
case AKBASIC_LEAF_COMMAND:
|
||||
case AKBASIC_LEAF_COMMAND_IMMEDIATE:
|
||||
@@ -437,10 +449,10 @@ akerr_ErrorContext *akbasic_leaf_to_string(akbasic_ASTLeaf *self, char *dest, si
|
||||
* The reference falls through to Go's %+v struct dump here, which has no
|
||||
* useful C equivalent. Print something a test can assert on instead.
|
||||
*/
|
||||
snprintf(dest, len, "(%s)", self->identifier);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "(%s)", self->identifier));
|
||||
break;
|
||||
default:
|
||||
snprintf(dest, len, "(leaf %d)", (int)self->leaftype);
|
||||
PASS(errctx, aksl_snprintf(&written, dest, len, "(leaf %d)", (int)self->leaftype));
|
||||
break;
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
|
||||
Reference in New Issue
Block a user