The variable parameters of a variadic function—that is, those that correspond with the position of the ellipsis—are interpreted by the va_arg()
macro. The va_arg()
macro is used to extract the next argument from an initialized argument list within the body of a variadic function implementation. The size of each parameter is determined by the specified type. If the type is inconsistent with the corresponding argument, the behavior is undefined and may result in misinterpreted data or an alignment error . (See see EXP36-C. Do not cast pointers into more strictly aligned pointer types).)
The variable arguments to a variadic function are not checked for type by the compiler. As a result, the programmer is responsible for ensuring that they are compatible with the corresponding parameter after the default argument promotions:
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
|
| Does not currently detect violations of this recommendation. Although the recommendation in general cannot be automated, because of the difficulty in enforcing contracts between a variadic function and its invokers, it would be fairly easy to enforce type correctness on arguments to the | |||||||
| CC2.DCL11 | Partially implemented | |||||||
|
| Warns about inconsistently typed arguments to formatted output functions when the | |||||||
| 41 S, 589 S | Partially implemented | |||||||
PRQA QA-C |
| 0179 (U) | Partially implemented |
Related Vulnerabilities
...