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
bool
checkPrintfFormat
(const ref Locloc
, scope const char[]format
, scope Expression[]args
, boolisVa_list
);Check that arguments to a printf
format
string 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
s
specifier - non-standard formats
- undefined behavior per C99
No attempt is made to fix the arguments or theformat
string.Parameters
Loc
loc
location for error messages
char[]
format
format
stringExpression[]
args
arguments to match with
format
stringbool
isVa_list
if a "v" function (
format
check only)Return Value
true
if errors occurredReferences: C99 7.19.6.1 http://www.cplusplus.com/reference/cstdio/printf/
-
Declaration
bool
checkScanfFormat
(const ref Locloc
, scope const char[]format
, scope Expression[]args
, boolisVa_list
);Check that arguments to a scanf
format
string 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 theformat
string.Parameters
Loc
loc
location for error messages
char[]
format
format
stringExpression[]
args
arguments to match with
format
stringbool
isVa_list
if a "v" function (
format
check only)Return Value
true
if errors occurredReferences: C99 7.19.6.2 http://www.cplusplus.com/reference/cstdio/scanf/