The internal routine behind the C I/O
functions—such as printf(), vsnprintf(), and snprintf()—reserves stack space for a format
conversion buffer. The buffer size is set by the macro FORMAT_CONVERSION_BUFFER, which is
defined in format.h. Consider the following issues before reducing the size of this
buffer:
- The default buffer size is 510 bytes. If MINIMAL is defined, the
size is set to 32, which allows integer values without width specifiers to be
printed.
- Each conversion specified with %xxxx (except %s) must fit in
FORMAT_CONVERSION_BUFSIZE. This means any individual formatted float or integer value,
accounting for width and precision specifiers, needs to fit in the buffer. Since the
actual value of any representable number should easily fit, the main concern is ensuring
the width and/or precision size meets the constraints.
- The length of converted strings using %s are unaffected by any change in
FORMAT_CONVERSION_BUFSIZE. For example, you can specify
printf("%s value is %d",
some_really_long_string,
intval)
without a
problem.
- The constraint is for each individual item being converted. For example a
format string of
%d item1 %f item2 %e item3
does not need to fit in the
buffer. Instead, each converted item specified with a % format must fit.
- There is no buffer overrun check.