Files
libakstdlib/tests/negative/format_mismatch.c
Logikoma acb47a0d56
All checks were successful
libakstdlib CI Build / cmake_build (push) Successful in 2m55s
libakstdlib CI Build / sanitizers (push) Successful in 2m57s
libakstdlib CI Build / coverage (push) Successful in 2m46s
libakstdlib CI Build / mutation_test (push) Successful in 18m29s
Preserve required snprintf length on truncation
2026-08-03 18:25:43 -04:00

27 lines
877 B
C

/*
* NEGATIVE COMPILE TEST.
*
* This file must NOT compile. It is built by the CTest entry
* `negative_format_mismatch` with -Werror, and that test is marked WILL_FAIL.
*
* What it asserts: the format attributes on the variadic wrappers are attached
* and effective. Going through a wrapper is exactly how a caller loses the
* compile-time format checking it would have had calling printf(3) directly --
* printf("%d", "str") is caught and an unattributed wrapper's equivalent is not.
* AKSL_PRINTF_FORMAT is what restores it, and this is what proves it is there.
*/
#include <akstdlib.h>
int main(void)
{
char buf[64];
int count = 0;
akerr_ErrorContext *raised = NULL;
/* %d against a string. This is the line that must not build. */
raised = aksl_snprintf(&count, buf, sizeof(buf), "%d", "not an int");
return raised == NULL ? 0 : 1;
}