Test aksl_vscanf, and drop a check that could not fail
Coverage caught both. aksl_vscanf was declared, documented and never called by anything, which is what 100% function coverage is for -- it is the only metric here that notices a whole function nobody exercises. aksl_vasprintf had a second vsnprintf whose return it compared against the first, and a CLEANUP block to free the buffer when they disagreed. They cannot disagree: the buffer was sized by vsnprintf from the same format string and the same arguments a few lines earlier. So that was a failure branch nothing can reach and a free() beneath it that nothing can execute -- exactly the dead code TODO.md 2.2.11 recorded against the old aksl_memset and aksl_memcpy, and removing those was the point. The invariant is a comment now, where it can be read. Back to 99.5% of lines (1708/1716) and 100% of functions (154/154), with the eight uncovered lines the ones TODO.md already accounts for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -567,6 +567,56 @@ static int test_scanf_reads_stdin(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The va_list form, used the way a consumer building its own wrapper would. */
|
||||
static akerr_ErrorContext AKERR_NOIGNORE *consumer_scan(const char *fmt, int expected,
|
||||
int *assigned, ...)
|
||||
{
|
||||
va_list args;
|
||||
akerr_ErrorContext *raised = NULL;
|
||||
|
||||
va_start(args, assigned);
|
||||
raised = aksl_vscanf(fmt, expected, assigned, args);
|
||||
va_end(args);
|
||||
return raised;
|
||||
}
|
||||
|
||||
static int test_vscanf_reads_stdin(void)
|
||||
{
|
||||
char path[AKSL_TMP_MAX];
|
||||
FILE *fp = NULL;
|
||||
akerr_ErrorContext *err = NULL;
|
||||
int a = 0;
|
||||
int assigned = 0;
|
||||
int saved = -1;
|
||||
int restored = -1;
|
||||
|
||||
AKSL_CHECK(aksl_temp_file(path, sizeof(path)) == 0);
|
||||
fp = fopen(path, "w");
|
||||
AKSL_CHECK(fp != NULL);
|
||||
AKSL_CHECK(fputs("33\n", fp) != EOF);
|
||||
AKSL_CHECK(fclose(fp) == 0);
|
||||
|
||||
saved = dup(fileno(stdin));
|
||||
AKSL_CHECK(saved >= 0);
|
||||
if ( freopen(path, "r", stdin) == NULL ) {
|
||||
close(saved);
|
||||
AKSL_CHECK(0);
|
||||
}
|
||||
|
||||
err = consumer_scan("%d", 1, &assigned, &a);
|
||||
|
||||
restored = dup2(saved, fileno(stdin));
|
||||
close(saved);
|
||||
clearerr(stdin);
|
||||
|
||||
AKSL_CHECK(restored >= 0);
|
||||
AKSL_CHECK(aksl_take(err) == 0);
|
||||
AKSL_CHECK(assigned == 1);
|
||||
AKSL_CHECK(a == 33);
|
||||
AKSL_CHECK(unlink(path) == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Files */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@@ -651,6 +701,7 @@ int main(void)
|
||||
AKSL_RUN(failures, test_fscanf_reads_from_a_stream);
|
||||
|
||||
AKSL_RUN(failures, test_scanf_reads_stdin);
|
||||
AKSL_RUN(failures, test_vscanf_reads_stdin);
|
||||
|
||||
AKSL_RUN(failures, test_remove_and_rename);
|
||||
AKSL_RUN(failures, test_mkstemp_and_mkdtemp);
|
||||
|
||||
Reference in New Issue
Block a user