# dmd.chkformat

Check the arguments to `printf` and `scanf` against the `format` string.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: chkformat.d

Documentation: https://dlang.org/phobos/dmd_chkformat.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/chkformat.d

- `checkPrintfFormat`

  #### Declaration

  `bool `checkPrintfFormat`(const ref Loc `loc`, scope const char[] `format`, scope Expression[] `args`, bool `isVa_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:

  1. incompatible sizes which will cause argument misalignment
  2. deferencing arguments that are not pointers
  3. insufficient number of arguments
  4. struct arguments
  5. array and slice arguments
  6. non-pointer arguments to `s` specifier
  7. non-standard formats
  8. undefined behavior per C99
  Per the C Standard, extra arguments are ignored.
  No attempt is made to fix the arguments or the `format` string.

  #### Parameters

  `Loc `loc`` | location for error messages
  `char[] `format`` | `format` string
  `Expression[] `args`` | arguments to match with `format` string
  `bool `isVa_list`` | if a "v" function (`format` check only)

  #### Return Value

  `true` if errors occurred

  References: C99 7.19.6.1 http://www.cplusplus.com/reference/cstdio/printf/

- `checkScanfFormat`

  #### Declaration

  `bool `checkScanfFormat`(const ref Loc `loc`, scope const char[] `format`, scope Expression[] `args`, bool `isVa_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:

  1. incompatible sizes which will cause argument misalignment
  2. deferencing arguments that are not pointers
  3. insufficient number of arguments
  4. struct arguments
  5. array and slice arguments
  6. non-standard formats
  7. undefined behavior per C99
  Per the C Standard, extra arguments are ignored.
  No attempt is made to fix the arguments or the `format` string.

  #### Parameters

  `Loc `loc`` | location for error messages
  `char[] `format`` | `format` string
  `Expression[] `args`` | arguments to match with `format` string
  `bool `isVa_list`` | if a "v" function (`format` check only)

  #### Return Value

  `true` if errors occurred

  References: C99 7.19.6.2 http://www.cplusplus.com/reference/cstdio/scanf/