35 lines
960 B
C
35 lines
960 B
C
|
|
#include "akerror.h"
|
||
|
|
#include "err_capture.h"
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
/*
|
||
|
|
* FAIL records the source file and function names with snprintf. Those names
|
||
|
|
* must be passed as %s ARGUMENTS, not used as the format string -- otherwise a
|
||
|
|
* path containing a printf conversion (say a build directory with a '%') is
|
||
|
|
* interpreted as a format and reads nonexistent varargs (undefined behavior).
|
||
|
|
*
|
||
|
|
* #line lets us make __FILE__ contain a conversion specifier; the stored name
|
||
|
|
* must come back verbatim.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#line 1 "pct%dname.c"
|
||
|
|
akerr_ErrorContext *raise_with_percent_in_filename(void)
|
||
|
|
{
|
||
|
|
PREPARE_ERROR(e);
|
||
|
|
FAIL_RETURN(e, AKERR_VALUE, "boom");
|
||
|
|
}
|
||
|
|
#line 22 "tests/err_format_string.c"
|
||
|
|
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
akerr_init();
|
||
|
|
|
||
|
|
akerr_ErrorContext *e = raise_with_percent_in_filename();
|
||
|
|
AKERR_CHECK(e != NULL);
|
||
|
|
AKERR_CHECK(strcmp(e->fname, "pct%dname.c") == 0);
|
||
|
|
|
||
|
|
e = akerr_release_error(e);
|
||
|
|
fprintf(stderr, "err_format_string ok\n");
|
||
|
|
return 0;
|
||
|
|
}
|