Take libakgl 0.7.0, and refuse an over-long type or field name
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 3m6s
akbasic CI Build / sanitizers (push) Failing after 3m59s
akbasic CI Build / coverage (push) Failing after 3m25s
akbasic CI Build / akgl_build (push) Failing after 20s
akbasic CI Build / mutation_test (push) Failing after 3m15s
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 3m6s
akbasic CI Build / sanitizers (push) Failing after 3m59s
akbasic CI Build / coverage (push) Failing after 3m25s
akbasic CI Build / akgl_build (push) Failing after 20s
akbasic CI Build / mutation_test (push) Failing after 3m15s
0.6.0 and 0.7.0 break nothing here: 0.6.0 is three arcade-physics fixes and a physics.max_timestep property this port does not use, and 0.7.0 reports failures libakstdlib's wrappers were already catching and takes libakerror 2.0.1 so it can drop the exit-status trap its own suites needed. That is the same defect include/akbasic/error.h guards for this band, now fixed at the source rather than worked around in two places. The floor moves to 0.7.0 anyway. The soname carries MAJOR.MINOR while the major is 0, so deciding for ourselves which of libakgl's minor releases were really compatible is exactly the judgement it exists to take away. 0.7.0 is largely about a defect class worth checking for here rather than assuming past: ten unterminated strncpy calls into fixed-width name fields. Ours are clean -- every one is bounded to size - 1 and every buffer is either explicitly terminated afterwards or memset first, checked site by site. But two of them, both written last week in src/structtype.c, truncated an over-long name silently, and truncation is an error everywhere else in this interpreter. It matters more for a name than for a value: two long type names trimmed to the same 31 characters collide, and the second is then reported as redeclaring a type the program never wrote. Both are refused now, showing the name as written. The check was unreachable as first drafted, because the prescan read words into a buffer the size of the limit and so trimmed them before anything could look -- the scratch is twice the limit now, which is what makes the two cases distinguishable at all. tests/struct_types.c pins that it stays reachable. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -218,6 +218,48 @@ static void test_declaration_errors_are_basic_errors(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief An over-long type or field name is refused, not silently trimmed.
|
||||
*
|
||||
* Truncation is an error everywhere else here, and it matters more for a name
|
||||
* than for a value: two long names trimmed to the same 31 characters would
|
||||
* collide, and the second would be reported as a redeclaration of a type the
|
||||
* program never wrote.
|
||||
*
|
||||
* The check was unreachable when it was first written, because the prescan read
|
||||
* words into a buffer the size of the limit and so trimmed them before anything
|
||||
* could look. Pinned here so it stays reachable.
|
||||
*/
|
||||
static void test_long_names_are_refused(void)
|
||||
{
|
||||
TEST_REQUIRE_OK(harness_start(NULL));
|
||||
TEST_REQUIRE_OK(akbasic_runtime_load(&HARNESS_RUNTIME,
|
||||
"10 TYPE AVERYVERYVERYLONGTYPENAMETHATGOESONANDON\n"
|
||||
"20 W#\n"
|
||||
"30 END TYPE\n"
|
||||
"40 PRINT 1\n"));
|
||||
TEST_REQUIRE_OK(akbasic_runtime_start(&HARNESS_RUNTIME, AKBASIC_MODE_RUN));
|
||||
TEST_REQUIRE_OK(akbasic_runtime_run(&HARNESS_RUNTIME, 0));
|
||||
TEST_REQUIRE(strstr(HARNESS_OUTPUT, "exceeds the 31 character limit") != NULL,
|
||||
"an over-long type name should be refused, got \"%s\"", HARNESS_OUTPUT);
|
||||
/* The whole name, not the trimmed one -- that is what makes it actionable. */
|
||||
TEST_REQUIRE(strstr(HARNESS_OUTPUT, "GOESONANDON") != NULL,
|
||||
"the refusal should show the name as written, got \"%s\"", HARNESS_OUTPUT);
|
||||
harness_stop();
|
||||
|
||||
TEST_REQUIRE_OK(harness_start(NULL));
|
||||
TEST_REQUIRE_OK(akbasic_runtime_load(&HARNESS_RUNTIME,
|
||||
"10 TYPE OKNAME\n"
|
||||
"20 AVERYVERYVERYLONGFIELDNAMETHATGOESON#\n"
|
||||
"30 END TYPE\n"
|
||||
"40 PRINT 1\n"));
|
||||
TEST_REQUIRE_OK(akbasic_runtime_start(&HARNESS_RUNTIME, AKBASIC_MODE_RUN));
|
||||
TEST_REQUIRE_OK(akbasic_runtime_run(&HARNESS_RUNTIME, 0));
|
||||
TEST_REQUIRE(strstr(HARNESS_OUTPUT, "exceeds the 31 character limit") != NULL,
|
||||
"an over-long field name should be refused, got \"%s\"", HARNESS_OUTPUT);
|
||||
harness_stop();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TEST_REQUIRE_OK(akbasic_error_register());
|
||||
@@ -228,6 +270,7 @@ int main(void)
|
||||
test_missing_field_lists_the_others();
|
||||
test_self_by_value_refused();
|
||||
test_declaration_errors_are_basic_errors();
|
||||
test_long_names_are_refused();
|
||||
|
||||
return akbasic_test_failures;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user