dmd.chkformat
Check the arguments to printf and scanf against the format string.
License
Source: chkformat.d
Documentation: https://dlang.org/phobos/dmd_chkformat.html
-
Declaration
boolcheckPrintfFormat(const ref Locloc, scope const char[]format, scope Expression[]args, boolisVa_list);Check that arguments to a printf
formatstring are compatible with that string. Issue errors for incompatibilities.Discussion
Follows the C99 specification for printf.
Takes a generous, rather than strict, view of compatiblity. For example, an unsigned value can be formatted with a signed specifier.
Diagnosed incompatibilities are:- incompatible sizes which will cause argument misalignment
- deferencing arguments that are not pointers
- insufficient number of arguments
- struct arguments
- array and slice arguments
- non-pointer arguments to
sspecifier - non-standard formats
- undefined behavior per C99
No attempt is made to fix the arguments or theformatstring.Parameters
Locloclocation for error messages
char[]formatformatstringExpression[]argsarguments to match with
formatstringboolisVa_listif a "v" function (
formatcheck only)Return Value
trueif errors occurredReferences: C99 7.19.6.1 https://www.cplusplus.com/reference/cstdio/printf/
-
Declaration
boolcheckScanfFormat(const ref Locloc, scope const char[]format, scope Expression[]args, boolisVa_list);Check that arguments to a scanf
formatstring are compatible with that string. Issue errors for incompatibilities.Discussion
Follows the C99 specification for scanf.
Takes a generous, rather than strict, view of compatiblity. For example, an unsigned value can be formatted with a signed specifier.
Diagnosed incompatibilities are:- incompatible sizes which will cause argument misalignment
- deferencing arguments that are not pointers
- insufficient number of arguments
- struct arguments
- array and slice arguments
- non-standard formats
- undefined behavior per C99
No attempt is made to fix the arguments or theformatstring.Parameters
Locloclocation for error messages
char[]formatformatstringExpression[]argsarguments to match with
formatstringboolisVa_listif a "v" function (
formatcheck only)Return Value
trueif errors occurredReferences: C99 7.19.6.2 https://www.cplusplus.com/reference/cstdio/scanf/